zoukankan      html  css  js  c++  java
  • C#版 分页导航条

    封装成静态方法,方便使用,代码如下:

    View Code
    /// <summary>
            /// 分页控件
            /// </summary>
            /// <param name="pageSize">分页大小</param>
            /// <param name="currentPage">当前页</param>
            /// <param name="totalCount">总记录数</param>
            /// <returns></returns>
            public static string ShowPageNavigate(int pageSize, int currentPage, int totalCount)
            {
                string redirecTo="";//跳转的页面
                //如果没有pageSize,默认设置为3
                pageSize = pageSize == 0 ? 3 : pageSize;
                int totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1);//总分页数
                var output = new StringBuilder();
                if (totalPages > 1)
                {
                    if (currentPage != 1)
                    {//处理首页链接                    
                        output.AppendFormat("<a class='pageLink' href='{0}?pageIndex=1&pageSize={1}'>首页</a>", redirecTo, pageSize);
                    }
                    if (currentPage > 1)
                    { //处理上一页
                        output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>上一页</a>", redirecTo, currentPage - 1, pageSize);
                    }
                    output.Append(" ");
                    int currint = 5;
                    for (int i = 0; i < 10; i++)
                    {//一共最多显示10个页码
                        if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
                        {//处理当前页面的前面5个,后面5个
                            if (currentPage == (currentPage + i - currint))
                            { //处理当前页
                                output.AppendFormat("<a class='cpb' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a>", redirecTo, currentPage, pageSize, currentPage);
                            }
                            else
                            {//处理其它页
                                output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a>", redirecTo, currentPage + i - currint, pageSize, currentPage + i - currint);
                            }
                        }
                        output.Append(" ");
                    }
                    if (currentPage < totalPages)
                    { //处理下一页
                        output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>下一页</a>",redirecTo,currentPage+1,pageSize);
                    }
                    if (currentPage != totalPages)
                    { //处理末页
                        output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>末页</a>",redirecTo,totalPages,pageSize);
                    }
                    output.Append(" ");
                }
                output.AppendFormat("第{0}页/共{1}页", currentPage, totalPages);//统计
                return output.ToString();
            }
  • 相关阅读:
    Django【十五】pillow模块使用
    Django【十四】内置的anth认证
    Django【十三】form组件。
    Django【十二】中间价
    Django【十一】cookie-sesson
    Django【十】Ajax
    Django【八】多表操作
    Django【九】事务和锁
    python协程
    python多线程
  • 原文地址:https://www.cnblogs.com/nianlee/p/2987117.html
Copyright © 2011-2022 走看看