关于在三层中使用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。
附图:

posted @   skybirdzw  阅读(95)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示