您的位置:首页 > 编程学习 > ASP.NET > 正文

ASP.NET自定义分页类

更多 时间:2014-11-14 类别:编程学习 浏览量:323

ASP.NET自定义分页类

ASP.NET自定义分页类

一、自定义分页类 PagerHelper

 

  •  
  • C# 代码   复制
  • 
     public class PagerHelper
        {
            private int _pageSize = 10;
            /// <summary>
            /// 每页默认10条数
            /// </summary>
            public int pageSize
            {
                get
                {
                    if (_pageSize < 1)
                        _pageSize = 1;
                    return _pageSize;
                }
                set { _pageSize = value; }
            }
    
            private int _extendPage = 5;
            /// <summary>
            /// 每页显示分页数
            /// </summary>
            public int extendPage
            {
                get
                {
                    if (_extendPage < 3)
                        _extendPage = 3;
                    return _extendPage;
                }
                set
                {
                    _extendPage = value;
                }
            }
    
            private int _currentPage = 1;
            /// <summary>
            /// 当前页码
            /// </summary>
            public int currentPage
            {
                get
                {
                    if (_currentPage < 1)
                        _currentPage = 1;
                    if (_currentPage > totalPages)
                        _currentPage = totalPages;
                    return _currentPage;
                }
                set
                {
                    _currentPage = value;
                }
            }
    
            private int _totalRows = 0;
            /// <summary>
            /// 总数据数
            /// </summary>
            public int totalRows
            {
                get { return _totalRows; }
                set { _totalRows = value; }
            }
    
            /// <summary>
            /// 分页时是否做urlRewriter处理
            /// </summary>
            private bool isRewrite
            {
                get { return pageUrl.IndexOf("{0}") > 0; }
            }
    
            private string _pageUrl = "";
            /// <summary>
            /// 分页url
            /// </summary>
            public string pageUrl
            {
                get { return _pageUrl; }
                set { _pageUrl = value; }
            }
    
            /// <summary>
            /// 总页数
            /// </summary>
            private int totalPages
            {
                get
                {
                    if ((totalRows % pageSize) == 0)
                    {
                        return (totalRows / pageSize);
                    }
                    return (totalRows / pageSize + 1);
                }
            }
    
            /// <summary>
            /// 上一页
            /// </summary>
            private int prevPage
            {
                get
                {
                    int temp = currentPage - 1;
                    if (temp < 1)
                    {
                        return 1;
                    }
                    return temp;
                }
            }
    
            /// <summary>
            /// 下一页
            /// </summary>
            private int nextPage
            {
                get
                {
                    int temp = currentPage + 1;
                    if (temp > totalPages)
                    {
                        return temp;
                    }
                    return temp;
                }
            }
    
    
      
    标签:分页
  • 您可能感兴趣