zoukankan      html  css  js  c++  java
  • asp.net分页方法

            /// </summary>
            /// <param name="ds">DataSet实例</param>
            /// <param name="datalistname">DataList名称</param>
            /// <param name="pagesize">分页大小</param>
            public static string GetPageNum(DataSet ds, DataList datalistname, int pagesize, int page)
            {
                // string sql0 = "SELECT TOP 10 * FROM Blobs WHERE id NOT IN(SELECT TOP (10*(2-1)) id FROM Blobs ORDER BY id) ORDER BY id select count(*) from Blobs";//两种分页sql
               // string sql = "SELECT TOP 5 * FROM (SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM Blobs) A WHERE RowNumber > 5*(" + page + "-1);select count(*) from Blobs";
                int total = (int)ds.Tables[1].Rows[0][0];//总页数
                datalistname.DataSource = ds.Tables[0];
                datalistname.DataBind();
                int allpage = 0;
                int next = 0;
                int pre = 0;
                int startcount = 0;
                int endcount = 0;
                string pagestr = "";
                if (page < 1) { page = 1; }
                //计算总页数
                if (pagesize != 0)
                {
                    allpage = (total / pagesize);
                    allpage = ((total % pagesize) != 0 ? allpage + 1 : allpage);
                    allpage = (allpage == 0 ? 1 : allpage);
                }
                next = page + 1;
                pre = page - 1;
                startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
                //中间页终止序号
                endcount = page < 5 ? 10 : page + 5;
                if (startcount < 1) { startcount = 1; } //为了避免输出的时候产生负数,设置如果小于1就从序号1开始
                if (allpage < endcount) { endcount = allpage; } //页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内
                pagestr = "<a >" + "" + allpage + "页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                pagestr += page > 1 ? "<a href="" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=1">首页</a>&nbsp;&nbsp;<a href="" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + pre + "">上一页</a>" : "<a>首页</a>" + "&nbsp;&nbsp;" + "<a>上一页</a>";
                //中间页处理,这个增加时间复杂度,减小空间复杂度
                for (int i = startcount; i <= endcount; i++)
                {
                    pagestr += page == i ? "&nbsp;&nbsp;" + "<strong><a class="cpb">" + i + "</a></strong>" : "&nbsp;&nbsp;<a href="" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + i + "">" + i + "</a>";
                }
                pagestr += page != allpage ? "&nbsp;&nbsp;<a href="" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + next + "">下一页</a>&nbsp;&nbsp;<a href="" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + allpage + "">末页</a>" : "&nbsp;&nbsp;" + "<a >下一页</a>" + "&nbsp;&nbsp;" + "<a >末页</a>";
                return pagestr;
            }
  • 相关阅读:
    3927Circular Sequence 思维题(求环形最大子列和)
    Rotational Painting(hdu 3685 凸包+多边形重心 模板题
    模拟 3897: Catch the Mouse
    L3-010 是否完全二叉搜索树 (30分)
    已知两种遍历顺序 推剩下的一种
    进阶实验4-3.3 完全二叉搜索树 (30分)->排序得出搜索树中序遍历->已知搜索树中序求层序
    任意进制转化/模板(c++/ java)
    4038: Robot Navigation --bfs(求最短路及其路径条数)
    A Simple Math Problem(hdu 5974 数论题
    LCM Walk(hdu 5584;数论题
  • 原文地址:https://www.cnblogs.com/zxiong/p/4105728.html
Copyright © 2011-2022 走看看