• AspNetPager分页实际应用


    ---恢复内容开始---

    首先,这个分页是快速开发的一种,弊端就是一次查询数据库全部,然后分页显示.

    注意:

    1,最好绑定的数据是一个list格式!

    1首先打开 

    http://www.webdiyer.com 下载AspNetPager

    然后引用这个dll文件

    然后在aspx前台最上面引用该dll

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

    2 在展示数据用的一些控件下面复制上

     <webdiyer:AspNetPager ID="AspNetPager1"   runat="server" FirstPageText="首页" LastPageText="最后一页"
            NextPageText="下一页" PrevPageText="上一页" OnPageChanged="AspNetPager1_PageChanged"
            Font-Size="X-Large" ForeColor="#336699" HorizontalAlign="Center">
        </webdiyer:AspNetPager>

    3 在后台要写上这样一个方法

     protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindDataTable();
        }

     BindDataTable();这个方法就是绑定数据的方法
    private void BindDataTable()
        {
            StringBuilder sb = new StringBuilder();

        //GetAllList 是查询数据,返回的是DataSet格式的, DataSet ds = bll.GetAllList(sb.ToString());
         //计算总共有多少条 AspNetPager1.RecordCount
    = ds.Tables[0].Rows.Count;
        //每页显示多少条 AspNetPager1.PageSize
    = 10; PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].Rows.ToString(); pds.AllowCustomPaging = true; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; pds.PageSize = AspNetPager1.PageSize; pagesize = AspNetPager1.PageSize; int i = (pds.CurrentPageIndex) * pds.PageSize; pageindex = pds.CurrentPageIndex;
        //这是创建一个实体类,来把DataSet格式转换list格式 List
    <ChaxunClass> list = new List<ChaxunClass>();
        //遍历数据,已list格式输出
    foreach (DataRow row in ds.Tables[0].Rows) {
           ChaxunClass cl
    = new ChaxunClass(); cl.num = row["第三方卡"].ToString(); list.Add(cl); } this.Repeater1.DataSource = list.Skip((pds.CurrentPageIndex) * pds.PageSize).Take(pds.PageSize); ; this.Repeater1.DataBind(); }
     以上是最初的 ,后来研究下  还是在这样方便,一个分页干吗要用2个控件
    后台改成,
      DataSet ds = bll.GetAllList(sb.ToString());
            int PageCount = AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
            pagesize = AspNetPager1.PageSize = 10;
            pageindex = AspNetPager1.CurrentPageIndex;
            List<ChaxunClass> list = new List<ChaxunClass>();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ChaxunClass cl = new ChaxunClass();
                cl.num = row["第三方卡"].ToString();
                list.Add(cl);
            }
            this.Repeater1.DataSource = list.Skip((pagesize) * (pageindex - 1)).Take(pagesize);
            this.Repeater1.DataBind();

    前台索引自增排序这样写

     <%# (pageindex - 1) *pagesize +Container.ItemIndex + 1%> 

     倒序排序这样写

        <%# (PageCount - (pageindex - 1) * pagesize)-Container.ItemIndex%>
     
  • 相关阅读:
    如何在intellj Idea中给新建的项目添加jar包?
    sell
    3D立体方块旋转图册
    npm run eject 命令后出现This git repository has untracked files or uncommitted changes错误
    video标签使用积累+背景视频+遇到问题(视频无法显示,不能自动播放,video自适应div,控件隐藏)
    webpack——react
    webpack——bable-loader,core,preset,编译es6
    webpack——打包JS
    简单的前端上传图片代码
    node——文件写入,文件读取
  • 原文地址:https://www.cnblogs.com/crazyair/p/3722756.html
Copyright © 2020-2023  润新知