首页 > 代码库 > 分页类
分页类
/// <summary> /// 分页 /// </summary> /// <typeparam name="T">类型</typeparam> public class PagedList<T> : List<T> { /// <summary> /// 缓存分页构造函数 /// </summary> /// <param name="source">数据源</param> /// <param name="pageIndex">当前页页码</param> /// <param name="pageSize">每页显示记录数</param> public PagedList(IQueryable<T> source, int pageIndex, int pageSize) { if (source == null || !source.Any()) throw new ArgumentNullException("source"); int total = source.Count(); TotalCount = total; TotalPages = total/pageSize; if (total%pageSize > 0) TotalPages++; PageSize = pageSize; PageIndex = pageIndex; AddRange(source.Skip(pageIndex*pageSize).Take(pageSize).ToList()); } /// <summary> /// 缓存分页构造函数 /// </summary> /// <param name="source">数据源</param> /// <param name="pageIndex">当前页页码</param> /// <param name="pageSize">每页显示记录数</param> public PagedList(IList<T> source, int pageIndex, int pageSize) { if (source == null || !source.Any()) throw new ArgumentNullException("source"); TotalCount = source.Count(); TotalPages = TotalCount/pageSize; if (TotalCount%pageSize > 0) TotalPages++; PageSize = pageSize; PageIndex = pageIndex; AddRange(source.Skip(pageIndex*pageSize).Take(pageSize).ToList()); } /// <summary> /// 非缓存分页构造函数 /// </summary> /// <param name="source">数据源</param> /// <param name="pageIndex">当前页页码</param> /// <param name="pageSize">每页显示记录数</param> /// <param name="totalCount">总记录数</param> public PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount) { if (source == null || !source.Any()) throw new ArgumentNullException("source"); TotalCount = totalCount; TotalPages = TotalCount/pageSize; if (TotalCount%pageSize > 0) TotalPages++; PageSize = pageSize; PageIndex = pageIndex; AddRange(source); } /// <summary> /// 当前页页码 /// </summary> public int PageIndex { get; private set; } /// <summary> /// 每页显示记录数 /// </summary> public int PageSize { get; private set; } /// <summary> /// 总记录数 /// </summary> public int TotalCount { get; private set; } /// <summary> /// 总页数 /// </summary> public int TotalPages { get; private set; } /// <summary> /// 有上一页 /// </summary> public bool HasPreviousPage { get { return (PageIndex > 0); } } /// <summary> /// 有下一页 /// </summary> public bool HasNextPage { get { return (PageIndex + 1 < TotalPages); } } }
分页类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。