标签:
AspNetPager使用方法:
1、首先引用AspNetPager.dll;
2、在所使用的前台页面加入:<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>,
指明DLL地址和命名空间;
3、在页面使用aspnetPager控件:(根据情况,自定义下面的属性)
<webdiyer:AspNetPager ID="AspNetPager1" class="quotes" runat="server" CustomInfoHTML="<span class="pageDesc">共有 %RecordCount%页 %CurrentPageIndex% / %PageCount% 页</span>"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" Width="95%"
CustomInfoStyle="" PagingButtonsClass="PageButton" AlwaysShowFirstLastPageNumber="True"
CurrentPageButtonClass="PageButtonCurrent" PagingButtonSpacing="2px" PagingButtonsStyle=""
ShowPageIndexBox="Never" CurrentPageButtonStyle="" LayoutType="Table" OnPageChanging="AspNetPager1_PageChanging"
ShowCustomInfoSection="Left">
</webdiyer:AspNetPager>
标红的是点击触发事件:
在.cs后台页面加上此方法:
private void BindGridView(string searchTableName)
{
string sortExpression = gvInDepot.Attributes["SortExpression"] == null ? "Code" : gvInDepot.Attributes["SortExpression"];
bool isASCDirection = gvInDepot.Attributes["SortDirection"] == "ASC" ? true : false;
//int totalCounts = (int)SqlHelper.GetCountNumber(searchTableName, "ID", "1=1");
int totalCounts = SqlHelper.SelectTable("*", searchTableName, "1=1", "ID", true).Rows.Count;
AspNetPager1.RecordCount = totalCounts;
if (totalCounts > 0)
{
gvInDepot.DataSource = SqlHelper.GetPagedData(searchTableName, "1=1", sortExpression, isASCDirection, AspNetPager1.StartRecordIndex,
AspNetPager1.EndRecordIndex);
gvInDepot.DataBind();
}
else
{
ShowGridViewTitle();
}
}
写到这里运行的确是没问题了,但是点击翻页就发现数据都是一样的,为什么呢?的确我们忘记了一件事,分页改变事件:
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
int tableCount = 0;
string searchTable = creatSearchTable(out tableCount);
BindGridView(searchTable);
}
4、同时,还要指定以下值:
AspNetPager1.PageSize=10;//每页显示多少条记录
AspNetPager1.RecordCount=100;//总页数
5、因为该控件与数据显示和绑定是独立的,所以可以根据所要显示的页数AspNetPager1.CurrentPageIndex,取得该页数据datatable,然后再使用repeater等控件绑定:
Repeater1.DataSource = dt;
Repeater1.DataBind();
标签:
原文地址:http://www.cnblogs.com/BrokenIce/p/5095605.html