paging in asp.net mvc

后端 未结 4 1632
忘掉有多难
忘掉有多难 2021-01-23 03:11

i have an asp.net website where i do paging through on the code behind using:

    PagedDataSource objPds = new PagedDataSource
                                 {         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 03:51

    There is a good paging class example in the Nerd Dinner project:

    public class PaginatedList : List {
    
            public int PageIndex  { get; private set; }
            public int PageSize   { get; private set; }
            public int TotalCount { get; private set; }
            public int TotalPages { get; private set; }
    
            public PaginatedList(IQueryable source, int pageIndex, int pageSize) {
                PageIndex = pageIndex;
                PageSize = pageSize;
                TotalCount = source.Count();
                TotalPages = (int) Math.Ceiling(TotalCount / (double)PageSize);
    
                this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
            }
    
            public bool HasPreviousPage {
                get {
                    return (PageIndex > 0);
                }
            }
    
            public bool HasNextPage {
                get {
                    return (PageIndex+1 < TotalPages);
                }
            }
    

提交回复
热议问题