1. 首页
  2. 技术文章
  3. 拼分页方法
拼分页方法

public static string GetPaperHtml(int RecordCount, int PageIndex, int PageSize, string FunName, string FunParams)

        {

            StringBuilder sb = new StringBuilder();

            //页数

            int PageCount = RecordCount / PageSize;

            if (RecordCount % PageSize > 0)

            {

                PageCount++;

            }

            //页码显示

            if (PageCount > 1)

            {

                sb.Append("<div class=\"gkPage\">");

                sb.AppendFormat("总条数:{0}|当前第{1}/{2}页", RecordCount, PageIndex, PageCount);

                if (PageIndex == 1)

                {

                    sb.Append("<span class=\"disable_pager\">首页</span>");

                    sb.Append("<span class=\"disable_pager\">上一页</span>");

                }

                else

                {

                    sb.AppendFormat("<a class=\"first_pager\" href=\"javascript:void(0);\" onclick=\"{0}(1{1})\">首页</a>", FunName, FunParams);

                    sb.AppendFormat("<a class=\"prev_pager\" href=\"javascript:void(0);\" onclick=\"{1}({0}{2})\">上一页</a>", PageIndex - 1, FunName, FunParams);

                }

                int ShowMaxPageIndexCount = 5;

                int ShowStartPageIndex = ((PageIndex - 1) / ShowMaxPageIndexCount) * ShowMaxPageIndexCount;

                int ShowLastPageIndex = ((ShowStartPageIndex + ShowMaxPageIndexCount) > PageCount) ? PageCount : (ShowStartPageIndex + ShowMaxPageIndexCount);

                if (ShowStartPageIndex > 0)

                {

                    sb.AppendFormat("<a class=\"pager\" href=\"javascript:void(0);\" onclick=\"{1}({0}{2})\">...</a>", ShowStartPageIndex, FunName, FunParams);

                }

                for (int i = ShowStartPageIndex + 1; i <= ShowLastPageIndex; i++)

                {

                    if (i == PageIndex)

                    {

                        sb.AppendFormat("<span class=\"current_pager\">{0}</span>", i);

                    }

                    else

                    {

                        sb.AppendFormat("<a class=\"pager\" href=\"javascript:void(0);\" onclick=\"{1}({0}{2})\">{0}</a>", i, FunName, FunParams);

                    }

                }

                if ((PageCount > ShowMaxPageIndexCount) && (ShowLastPageIndex < PageCount))

                {

                    sb.AppendFormat("<a class=\"pager\" href=\"javascript:void(0);\" onclick=\"{1}({0}{2})\">...</a>", ShowLastPageIndex + 1, FunName, FunParams);

                }

                if (PageIndex == PageCount)

                {

                    sb.Append("<span class=\"disable_pager\">下一页</span>");

                    sb.Append("<span class=\"disable_lastpager\">尾页</span>");

                }

                else

                {

                    sb.AppendFormat("<a class=\"next_pager\" href=\"javascript:void(0);\" onclick=\"{1}({0}{2})\">下一页</a>", PageIndex + 1, FunName, FunParams);

                    sb.AppendFormat("<a class=\"last_pager\" href=\"javascript:void(0);\" onclick=\"{1}({0}{2})\">尾页</a>", PageCount, FunName, FunParams);

                }

                sb.Append("</div></div>");

            }

            return sb.ToString();

        }


友情连接

Copyright ©2012-2016www.CSAspx.com 湘ICP备16005320号-1

声明:本站资源部分收集于互联网和用户上传源码,分享目的仅供大家学习与参考,如有侵权,请联系240852963@qq.com及时删除,本站不承担法律责任!

站点地图