ASP.NET使用AspNetPager实现翻页功能

ASP.NET使用AspNetPager实现翻页功能

一、前端aspx网页

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged" PageSize="1" CustomInfoHTML="第 <font color=‘red‘><b>%currentPageIndex%</b></font> 页,共 %PageCount% 页,每页显示 %PageSize% 条记录,共 %RecordCount% 条记录" FirstPageText="第一页" PrevPageText="上一页" NextPageText="下一页" LastPageText="最末页" CustomInfoTextAlign="Center" CssClass="white" ShowCustomInfoSection="Left" AlwaysShow=true SubmitButtonText="Go" PageIndexBoxType="DropDownList" ShowBoxThreshold="10" ShowPageIndexBox="Auto" TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到">

</webdiyer:AspNetPager>

二、后台aspx

1.窗体加载Page_Load

AspNetPager1.RecordCount = (int)Cqzxw.SqlData.ExecuteScalar("Select count(*) From 表名");

ShowData();//绑定数据方法

2.数据绑定

private void ShowData()

{

   DataSet ds =Cqzxw.SqlData.ExecuteDataSet("Select * From 表名", AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);

   GridView1.DataSource = ds;

   GridView1.DataBind();

}

3.翻页改变事件

protected void AspNetPager1_PageChanged(object sender, EventArgs e)

{

   ShowData();

}

相关文章