ASP.NET分页存储过程及调用(二)

2015-07-24 10:44:17 · 作者: · 浏览: 8
= Convert.ToInt32(Request["Page"]); } else { PageIndex = 1; } } private void showData() { list = new DataTable(); int PageSize = 10; Pager pager = new Pager(PageIndex); DivPager = pager.GetDivPager("", pager.LinkServer(" dbo.ze_user ", "*",""," desc "," Id "," Id ",ref PageSize,ref PageIndex), out list); } } }
 
 
5.GetDivPager拼接字符串

queryString       如果需要在URL加参数,比如:&charset=utf-8
ds                      从存储过程的取得数据集
dt                       将列表数据返回
返回值               HTML标签  ?

        public string GetDivPager(string queryString, DataSet ds, out DataTable dt) 
        { 
            StringBuilder sp = new StringBuilder();
            int PageSize = 10;
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

                int TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());
                int rowCount = (TotalCount % PageSize != 0) ? TotalCount / PageSize + 1 : TotalCount / PageSize;
                if (dt != null && dt.Rows.Count > 0)
                {
                    sp.AppendFormat("  

总记录:{0}", TotalCount); sp.AppendFormat(" 页码:{0}/{1} ", PageIndex, rowCount); sp.AppendFormat(" 每页:{0}

", PageSize); sp.AppendFormat("
"); sp.AppendFormat(" 首页 ", "?page=1" + queryString); if (PageIndex > 1) { sp.AppendFormat(" < 上一页 ", "?page=" + (PageIndex - 1) + queryString); } int temp = 0; int loopc = rowCount > 10 ? 10 : rowCount; for (int i = 0; i < loopc; i++) { temp = i + 1; if (PageIndex > 10) { temp = (PageIndex - 10) + i + 1; } sp.AppendFormat(" {2}", PageIndex == temp ? "active" : "", "?page=" + temp + queryString, temp); } if (PageIndex != rowCount) { sp.AppendFormat(" 下一页 >", "?page=" + (PageIndex + 1) + queryString); } sp.AppendFormat(" 尾页", "?page=" + rowCount + queryString); sp.AppendFormat("
"); } } else { dt = null; } return sp.ToString(); }

?

 
 

?

6.页面显示

?

 	
                <%if (list != null && list.Rows.Count > 0)
                  {
                      int abc = 1;
                      foreach (System.Data.DataRow item in list.Rows)
                      {%>
                
                <%}
        }%>
            
序号 用户名 密码 创建时间
" /> <%=abc++ %> <%=item["UserName"]%> <%=item["PASSWORD"]%> <%=Convert.ToDateTime(item["CreateTime"]).ToString("yyyy-MM-dd hh:mm:ss") %>

?

OK!