• mvc分页类


        public class MyPager
        {
            /// <summary>
            /// 每页数据条数
            /// </summary>
            public int PageSize { get; set; }
            /// <summary>
            /// 总数据条数
            /// </summary>
            public int TotalCount { get; set; }
            /// <summary>
            /// 当前页码(从 1 开始)
            /// </summary>
            public int PageIndex { get; set; }
            /// <summary>
            ///  "/Role/List?pageIndex={pn}"
            /// </summary>
            public string UrlPattern { get; set; }
            /// <summary>
            /// 最多的页码数
            /// </summary> 
            public int MaxPagerCount { get; set; }
            /// <summary>
            /// 选中的类样式
            /// </summary>
            public string CurrentLinkClassName { get; set; }
            public MyPager()
            {
                this.PageSize = 10;
                this.MaxPagerCount = 10;
            }
            public string GetPager()
            {
                StringBuilder sb = new StringBuilder();
                //算出来的页数 
                int pageCount = (int)Math.Ceiling(TotalCount * 1.0f / PageSize);
                int startPageIndex = Math.Max(1, PageIndex - MaxPagerCount / 2);//第一个页码
                int endPageIndex = Math.Min(pageCount, startPageIndex + MaxPagerCount - 1); //最后一个页码 
                sb.AppendLine("<ul>");
                for (int i = startPageIndex; i <= endPageIndex; i++)
                {
                    if (i == PageIndex) { sb.AppendLine("<li class='" + CurrentLinkClassName + "'>" + i + "</li>"); }
                    else
                    {
                        sb.AppendLine("<li><a href='" + UrlPattern.Replace("{pn}", i.ToString()) + "'>" + i +"</a></li>");
                    }
                }
                sb.AppendLine("</ul>"); return sb.ToString();
            }//end GetPager
        }
  • 相关阅读:
    数据结构实验报告(四)
    数据结构实验报告(三)
    数据结构实验报告(一)
    数据结构实验报告(二)
    Java基础之排序
    1070 Mooncake
    1071 Speech Patterns
    1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
    5403. Find the Kth Smallest Sum of a Matrix With Sorted Rows
    1072 Gas Station
  • 原文地址:https://www.cnblogs.com/lierjie/p/12006542.html
Copyright © 2020-2023  润新知