前台代码:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<webdiyer:AspNetPager ID="AspNetPager1" CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" CurrentPageButtonClass="cpb" AlwaysShow="True" runat="server"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" ShowCustomInfoSection="Left"
ShowInputBox="Never" OnPageChanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList" CustomInfoTextAlign="Left" LayoutType="Table"
ShowPageIndexBox="Always" SubmitButtonText="Go" PageSize="12" TextAfterPageIndexBox="页"
TextBeforePageIndexBox="转到" Width="50" Font-Size="X-Small" Height="30">
</webdiyer:AspNetPager>
前台样式自己写就好了。
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
//获取数据
protected void BindData()
{
DataTable dt = PageBysql();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
Pager(this.Repeater1, this.AspNetPager1, ds);
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
protected void Pager(Repeater dl, Wuqi.Webdiyer.AspNetPager anp, System.Data.DataSet dst)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dst.Tables[0].DefaultView;
pds.AllowPaging = true;
anp.RecordCount = dst.Tables[0].DefaultView.Count;
pds.CurrentPageIndex = anp.CurrentPageIndex - 1;
pds.PageSize = anp.PageSize;
dl.DataSource = pds;
dl.DataBind();
}
如有不懂的可以私信我!