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();
}


posted @ 2011-01-20 17:59  web程序人生  阅读(1018)  评论(0编辑  收藏  举报