asp.net分页,ASPNETPager用法


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

<div id="PagerStyle">
<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"
CurrentPageButtonClass="cpb" CustomInfoHTML="当前第 %CurrentPageIndex%/ %PageCount% 共 %PageCount%页 每页 %PageSize% 条记录"AlwaysShowFirstLastPageNumber="True"LayoutType="Table">
</webdiyer:AspNetPager>
</div>

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

private void LoadData()
{
DataSet ds =BLL.Trunk.GetAllList();
PagedDataSource pds = newPagedDataSource();
pds.AllowPaging =true;//设置允许分页
pds.DataSource =ds.Tables[0].DefaultView;//设置分页的数据源
AspNetPager1.RecordCount = pds.Count;//AspNetPager1.RecordCount =ds.Tables[0].DefaultView.Count;等价//获取数据的条数
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex -1;//设置当前页的索引
pds.PageSize =AspNetPager1.PageSize;//设置每页显示的页数
gvData.DataSource = pds;
gvData.DataBind();
}

5.事件分页改变代码:

protected void AspNetPager1_PageChanging(object src,PageChangingEventArgs e)
{
this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex+ 1, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount,this.AspNetPager1.PageSize});
AspNetPager1.CurrentPageIndex =e.NewPageIndex;
LoadData();
}


转载于:https://www.cnblogs.com/chinawinner/archive/2011/01/20/tt144.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值