关于在三层中使用AspNetPager的记录
第一步:引用AspNetPager.dll到项目中
第二步:前端页面引用,示例如下:
//先在顶部注册这个控件
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
//然后,给该控件各个用到的属性赋值,此处注意PageSize这个属性。
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign="Right"
FirstPageText="首页" PrevPageText="上一页" NextPageText="下一页" LastPageText="末页" AlwaysShow="true"
onpagechanging="AspNetPager1_PageChanging" PageSize="9">
</webdiyer:AspNetPager>
第三步:在后台.cs文件中编写代码,如下:
if (!IsPostBack)
{
BindTheList();
}
protected void BindTheList()
{
//此处需要注意:检索数据时要把AspNetPager分页属性传进去,这样才能检索到想要的分页数据
//如:this.AspNetPager1.CurrentPageIndex-1为当前页索引;this.AspNetPager1.PageSize为页显示条数
list = Smartsite.Product.BLL.Product.Search(ref intRecordCount, this.AspNetPager1.CurrentPageIndex-1, this.AspNetPager1.PageSize, strKey, intNameorDepict, intCategoryID, 1, CategoryLevel, showChild);
if (list != null)
{
this.AspNetPager1.RecordCount = intRecordCount;
this.AspNetPager1.PageSize = PageCount;
this.AspNetPager1.CurrentPageIndex = intCurPage;
repList.DataSource = list;
repList.DataBind();
}
}
//还要为AspNetPager1控件添加AspNetPager1_PageChanging事件,并在事件中编写所需代码,如下:
protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
{
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BindTheList();
}
第四步:测试,OK。
附图:


浙公网安备 33010602011771号