AspNetPager分页控件
在写代码前确保AspNetPager.dll文件已经添加
在aspx页面中,添加引用如下图所示:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
控件的形式如下:
<Webdiyer:AspNetPager ID="MyPage" PageSize="15" CssClass="paginator" CurrentPageButtonClass="cpb"
FirstPageText="首页" NextPageText="下一页" LastPageText="尾页" PrevPageText="上一页" runat="server"
OnPageChanging="MyPage_PageChanging" ShowPageIndexBox="Always" AlwaysShow="true"
NumericButtonCount="5" >
</Webdiyer:AspNetPager> 每页15条数据,一直显示次空间,触发事件。
aspx.cs页面如下:
首先触发的事件:
protected void MyPage_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
MyPage.CurrentPageIndex = e.NewPageIndex;
BindData();
}
protected void BindData()
{
DataTable table = bll.AllFunction(); //从数据库中读取的数据
PagedDataSource pds = new PagedDataSource();
pds.DataSource = table.DefaultView;//设置分页的数据源
pds.AllowPaging = true;//设置允许分页
MyPage.RecordCount = pds.Count;//AspNetPager1.RecordCount = ds.Tables[0].DefaultView.Count;等价//获取数据的条数
pds.CurrentPageIndex = MyPage.CurrentPageIndex - 1;//设置当前页的索引
pds.PageSize = MyPage.PageSize;//设置每页显示的页数
this.GridViewUserInfo.DataSource = pds;
this.GridViewUserInfo.DataBind();//绑定数据
}
浙公网安备 33010602011771号