Asp.net不拖GridView控件,用Table实现其分页和删除

屁话:听人说通过拖控件开发出来的程序,运行效率都不怎么高。 确实,有的网站用拖控件一两天就可以做出来,但是全部靠拖控件会产生很多没有必要的垃圾代码,访问量少还好,但是如果一个网页多出10KB的垃圾代码,一个网站有100个网页,一个网页的访问量为1000。则10*100*1000/1024=1G,就会多出1G的访问流量。


所以我尽量不拖控件了。大概就是这个鬼样子的。额,就两个功能,删除和分页。


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="huiVip.aspx.cs" Inherits="B2C.Manage.huiVip" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style type="text/css">
        body{
            font-size:12px;
        }
        #th{
            background-color:#D2B48C;
        }
        #jishu{
            background-color:#FAFAD2;
        }
        #oushu{
            background-color:#EEE8AA;
        }
        table{
            border:solid #D2B48C 1px;
        }
        th{
            padding:3px 8px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="margin:20px 10px;">
    <h3>管理会员</h3>
    <table cellpadding="4" cellspacing="0">
        <tr align="center" id="th">
            <th>代号</th>
            <th>真是姓名</th>
            <th>电话号码</th>
            <th>会员Email</th>
            <th>详细地址</th>
            <th>邮政编码</th>
            <th>加入日期</th>
            <th></th>
        </tr>
        <%=ht %>
        <tr align="center">
            <td colspan="8" id="jishu">
                <%=yema %>
            </td> 
        </tr>
    </table>
    </div>
    </form>
</body>
    <script type="text/javascript">
        window.onload = function () {
            var de = document.getElementsByClassName('delete');
            for (var i = 0; i < de.length; i++) {
                de[i].onclick = function () {
                    return confirm('确认要删除!!', '提示');
                }
            }
        }
    </script>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace B2C.Manage
{
    public partial class huiVip : SessionLogin
    {
        public string ht = "";
        public string yema = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //删除
            if (Request.QueryString["id"] !=null)
            {
                string str = "delete [dbo].[tb_Member] where MemberID=@idde";
                string st = Request.QueryString["id"];
                SqlParameter[] parade =
                {
                    new SqlParameter("@idde",st)
                };
                try
                {
                    if (DBHelper.IDUBySql(str, parade))
                    {
                        Response.Write("<script>alert('删除成功!!')</script>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('"+ex.Message+"')</script>");
                }
            }
	
            int page =1;
            if (!int.TryParse(Request.QueryString["page"], out page))
            {
                page = 1;
            }
            string sql = "select MemberID,RealName,Phonecode,Email,[Address],PostCode,LoadDate from (select *,ROW_NUMBER() over(order by MemberID) as num from [dbo].[tb_Member]) as t where num>=@begin and num<=@end";
            SqlParameter[] para =
            {
                new SqlParameter("@begin",(page-1)*5),
                new SqlParameter("@end",page*5)
            };
            DataTable dt = new DataTable();
            dt = DBHelper.GetTableBySql(sql, para);
            StringBuilder sb = new StringBuilder();
            string s = string.Empty;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                s = i % 2 != 0 ? "oushu" : "jishu";
                sb.Append("<tr align=\"center\" id=\"" + s + "\"><td>" + dt.Rows[i][0].ToString() + "</td><td>" + dt.Rows[i][1].ToString() + "</td><td>" + dt.Rows[i][2].ToString() + "</td><td>" + dt.Rows[i][3].ToString() + "</td><td>" + dt.Rows[i][4].ToString() + "</td><td>" + dt.Rows[i][5].ToString() + "</td><td>" + dt.Rows[i][6].ToString() + "</td><td><a class=\"delete\" href=\"huiVip.aspx?id=" + dt.Rows[i][0].ToString() + "\">删除</a></td></tr>");
            }
            ht = sb + "";

            //页码的
            string strco = "select COUNT(*) from [dbo].[tb_Member]";
            int conut = DBHelper.GetTableBySqlConut(strco,null);

            for (int i = 1; conut > 0; i++)
            {
                yema=yema+ " <a href=\"huiVip.aspx?page="+i+"\">" + i+"</a> ";
                conut -= 5;
            }
        }
    }
}



已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页