zoukankan      html  css  js  c++  java
  • ASP.Net分页方法详解

    1.添加DLL引用,文件名为:AspNetPager.dll。
    2.在aspx文件中添加<%@ RegisterAssembly="AspNetPager" Namespace="Wuqi.Webdiyer"TagPrefix="webdiyer" %>代码,下面是分页样式代码:

     

    3.在CS文件中写using Wuqi.Webdiyer;
    4.获取数据源,下面是获得数据的一个方法,BLL.Trunk.GetAllList方法是一个封装过的方法,返回一个DataSet结果集,这个方法自己写就可以,这是来自项目中的代码:

     

    View Code
    1 private void LoadData()
    2 {
    3 DataSet ds =BLL.Trunk.GetAllList();
    4 PagedDataSource pds = newPagedDataSource();
    5 pds.AllowPaging =true;//设置允许分页
    6 pds.DataSource =ds.Tables[0].DefaultView;//设置分页的数据源
    7 AspNetPager1.RecordCount = pds.Count;//AspNetPager1.RecordCount =ds.Tables[0].DefaultView.Count;等价//获取数据的条数
    8 pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex -1;//设置当前页的索引
    9 pds.PageSize =AspNetPager1.PageSize;//设置每页显示的页数
    10 gvData.DataSource = pds;
    11 gvData.DataBind();
    12 }

    5.事件分页改变代码:

    

    View Code
    1 protected void AspNetPager1_PageChanging(object src,PageChangingEventArgs e)
    2 {
    3 this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex+ 1, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount,this.AspNetPager1.PageSize});
    4 AspNetPager1.CurrentPageIndex =e.NewPageIndex;
    5 LoadData();
    6 }

    View Code
    1 <div id="PagerStyle">
    2  <webdiyer:AspNetPager ID="AspNetPager1"runat="server" OnPageChanging="AspNetPager1_PageChanging"Width="95%" PageSize="20" AlwaysShow="True" FirstPageText="首页"LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"ShowCustomInfoSection="Left" ShowInputBox="Never"CustomInfoTextAlign="Right"CssClass="paginator"
    3 CurrentPageButtonClass="cpb" CustomInfoHTML="当前第 %CurrentPageIndex%/ %PageCount% 共 %PageCount%页 每页 %PageSize% 条记录"AlwaysShowFirstLastPageNumber="True"LayoutType="Table">
    4  </webdiyer:AspNetPager>
    5  </div>
  • 相关阅读:
    Traefik2.X 版本 中 URL Rewrite 的使用
    图144 超音速客机
    ingressnginx 的使用 =》 部署在 Kubernetes 集群中的应用暴露给外部的用户使用
    在k8s集群中安装rookceph 1.8版本步骤
    Traefik 2.0 暴露 Redis(TCP) 服务
    Traefik 2.0 实现自动化 HTTPS
    Kubernetes的kubectl常用命令速记
    docker运行tomcat的war包程序,构建镜像
    使用Prometheus和Grafana监控RabbitMQ集群 (使用RabbitMQ自带插件)
    使用Prometheus和Grafana监控nacos集群
  • 原文地址:https://www.cnblogs.com/wsl2011/p/2063517.html
Copyright © 2011-2022 走看看