English versionEnglish
博杨计算机有限公司

MvcPager分页控件

MvcPager源代码—PagedList.cs

using System;
using System.Collections.Generic;

namespace Webdiyer.WebControls.Mvc
{
    public class PagedList<T> : List<T>
    {
        public PagedList(IList<T> items,int pageIndex,int pageSize)
        {
            PageSize = pageSize;
            TotalItemCount = items.Count;
            TotalPageCount = (int)Math.Ceiling(TotalItemCount / (double)PageSize);
            CurrentPageIndex = pageIndex;
            StartRecordIndex=(CurrentPageIndex - 1) * PageSize + 1;
            EndRecordIndex = TotalItemCount>pageIndex*pageSize?pageIndex*pageSize:TotalItemCount;
            for (int i = StartRecordIndex-1; i < EndRecordIndex;i++ )
            {
                Add(items[i]);
            }
        }

        public PagedList(IEnumerable<T> items, int pageIndex, int pageSize, int totalItemCount)
        {
            AddRange(items);
            TotalItemCount = totalItemCount;
            TotalPageCount = (int)Math.Ceiling(totalItemCount / (double)pageSize);
            CurrentPageIndex = pageIndex;
            PageSize = pageSize;
            StartRecordIndex = (pageIndex - 1) * pageSize + 1;
            EndRecordIndex = TotalItemCount>pageIndex*pageSize?pageIndex*pageSize:totalItemCount;
        }

        public int CurrentPageIndex { get; set; }
        public int PageSize { get; set; }
        public int TotalItemCount { get; set; }
        public int TotalPageCount{get; private set;}
        public int StartRecordIndex{get; private set;}
        public int EndRecordIndex{get; private set;}
    }
}