zoukankan      html  css  js  c++  java
  • mvc.net分页查询案例——PagedList

    在.net中,除了人手动写分页类之外,微软还提供了官方的分页,分页工具类包括PagedList和PagerExtension,先来看看PagedList类里面是怎么写的:

    PagedList

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace System.Web.Mvc
    {
        public class PagedList<T> : List<T>
        {
    
            /// <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 List<T> Source { get; private set; }
    
    
            public  PagedList(List<T> source, int pageIndex, int pageSize, int totalCount)
            {
                PageIndex = pageIndex;
                PageSize = pageSize;
                TotalCount = totalCount;
                TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
                this.AddRange( source.Take(source.Count));
            }
            public  PagedList()
            {}
            /// <summary>
            /// 是否包含上一页
            /// </summary>
            public bool HasPreviousPage
            {
                get
                {
                    return (PageIndex > 1);
                }
            }
    
            public bool HasNextPage
            {
                get
                {
                    return (PageIndex  < TotalPages);
                }
            }
        }
    }


  • 相关阅读:
    不可或缺 Windows Native (15)
    不可或缺 Windows Native (14)
    不可或缺 Windows Native (13)
    不可或缺 Windows Native (12)
    不可或缺 Windows Native (11)
    不可或缺 Windows Native (10)
    不可或缺 Windows Native (9)
    不可或缺 Windows Native (8)
    不可或缺 Windows Native (7)
    不可或缺 Windows Native (6)
  • 原文地址:https://www.cnblogs.com/a1111/p/7459645.html
Copyright © 2011-2022 走看看