c#分頁工具類,完美實現List分頁


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectProgress.BLL
{
    /// <summary>
    /// 分頁工具類
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PagingUtil<T> : List<T>
    {
        public int DataCount { get; set; } //總記錄數
        public int PageCount { get; set; } //總頁數
        public int PageNo { get; set; } //當前頁碼
        public int PageSize { get; set; } //每頁顯示記錄數
        //是否有上一頁
        public bool HasPreviousPage
        {
            get { return PageNo > 1; }
        }

        //是否有下一頁
        public bool HasNextPage
        {
            get { return PageNo < this.PageCount; }
        }

        /// <summary>
        /// 構造方法
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageNo"></param>
        public PagingUtil(List<T> dataList, int pageSize, int pageNo)
        {
            this.PageSize = pageSize;
            this.PageNo = pageNo;
            this.DataCount = dataList.Count;
            this.PageCount = (int) Math.Ceiling((decimal) this.DataCount/pageSize);
            this.AddRange(dataList.Skip((pageNo - 1)*pageSize).Take(pageSize));
        }
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM