ASP.Net分页方法详解

1.添加DLL引用,文件名为:AspNetPager.dll。
2.在aspx文件中添加<%@ RegisterAssembly="AspNetPager" Namespace="Wuqi.Webdiyer"TagPrefix="webdiyer" %>代码,下面是分页样式代码:

 

3.在CS文件中写using Wuqi.Webdiyer;
4.获取数据源,下面是获得数据的一个方法,BLL.Trunk.GetAllList方法是一个封装过的方法,返回一个DataSet结果集,这个方法自己写就可以,这是来自项目中的代码:

 

ContractedBlock.gif ExpandedBlockStart.gif View Code
 
   
1 private void LoadData()
2 {
3 DataSet ds = BLL.Trunk.GetAllList();
4 PagedDataSource pds = newPagedDataSource();
5 pds.AllowPaging = true ; // 设置允许分页
6 pds.DataSource = ds.Tables[ 0 ].DefaultView; // 设置分页的数据源
7 AspNetPager1.RecordCount = pds.Count; // AspNetPager1.RecordCount =ds.Tables[0].DefaultView.Count;等价 // 获取数据的条数
8 pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1 ; // 设置当前页的索引
9 pds.PageSize = AspNetPager1.PageSize; // 设置每页显示的页数
10 gvData.DataSource = pds;
11 gvData.DataBind();
12 }

5.事件分页改变代码:



ContractedBlock.gif ExpandedBlockStart.gif View Code
 
   
1 protected void AspNetPager1_PageChanging( object src,PageChangingEventArgs e)
2 {
3 this .AspNetPager1.CustomInfoHTML = string .Format( " 当前第{0}/{1}页共{2}条记录 每页{3}条 " , new object [] { this .AspNetPager1.CurrentPageIndex + 1 , this .AspNetPager1.PageCount, this .AspNetPager1.RecordCount, this .AspNetPager1.PageSize});
4 AspNetPager1.CurrentPageIndex = e.NewPageIndex;
5 LoadData();
6 }
ContractedBlock.gif ExpandedBlockStart.gif View Code
 
   
1 < div id = " PagerStyle " >
2   < webdiyer:AspNetPager ID = " AspNetPager1 " runat = " server " OnPageChanging = " AspNetPager1_PageChanging " Width = " 95% " PageSize = " 20 " AlwaysShow = " True " FirstPageText = " 首页 " LastPageText = " 尾页 " NextPageText = " 下一页 " PrevPageText = " 上一页 " ShowCustomInfoSection = " Left " ShowInputBox = " Never " CustomInfoTextAlign = " Right " CssClass = " paginator "
3 CurrentPageButtonClass = " cpb " CustomInfoHTML = " 当前第 %CurrentPageIndex%/ %PageCount% 共 %PageCount%页 每页 %PageSize% 条记录 " AlwaysShowFirstLastPageNumber = " True " LayoutType = " Table " >
4   </ webdiyer:AspNetPager >
5   </ div >

转载于:https://www.cnblogs.com/wsl2011/archive/2011/05/30/2063517.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值