0

我正在使用 nop commercer2.6 所以我想创建自定义报告,并且我想为该报告进行分页。

这是我的功能

 public virtual IPagedList<HireItemReportLine> HireItemReport(int ceremony_id, string Fname, string Mname, string Lnmae, string emailAdd, int sesson_id, int pageIndex, int pageSize)
        {

            var query1 = from opv in _opvRepository.Table
                         join o in _orderRepository.Table on opv.OrderId equals o.Id
                         join gr in _graduandRepository.Table on opv.graduand_id equals gr.Id
                         join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
                         join p in _productRepository.Table on pv.ProductId equals p.Id
                         join c in _ceremonyRepository.Table on gr.ceremony_id equals c.Id
                         join s in _seasonRepository.Table on c.season_id equals s.Id
                         where (!o.Deleted) && (opv.IsHireItem == true) &&
                         (!p.Deleted) &&
                         (!pv.Deleted)
                         select new
                         {
                             opvTable = opv,
                             grTable = gr,
                             seaTable = s,

                         };

            if (!(sesson_id == 0))
                query1 = query1.Where(item => item.seaTable.Id == sesson_id);

             if (!(ceremony_id == 0))                 
                 query1 = query1.Where(item => item.opvTable.ceremony_id == ceremony_id);

             if (!String.IsNullOrEmpty(Fname))
                 query1 = query1.Where(item => item.grTable.first_name == Fname);

             if (!String.IsNullOrEmpty(Mname))
                 query1 = query1.Where(item => item.grTable.middle_name == Mname);

             if (!String.IsNullOrEmpty(Lnmae))
                 query1 = query1.Where(item => item.grTable.last_name == Lnmae);

             if (!String.IsNullOrEmpty(emailAdd))
                 query1 = query1.Where(item => item.grTable.email == emailAdd);


             var query2 = from opv in query1
                          group opv by opv.opvTable.OrderId into g
                          select new
                          {
                              OrderId = g.Key,
                              TotalAmount = g.Sum(x => x.opvTable.PriceInclTax),


                          };
 int totalCount = query2.Count();
             query2 = query2.OrderByDescending(x => x.OrderId);

             var result = query2.ToList().Select(x =>
            {
                return new HireItemReportLine()
                {
                    OrderId = x.OrderId,                   
                    Amount= x.TotalAmount,

                };
            });

             var orders_1 = result.ToList();       


             return new PagedList<HireItemReportLine>(orders_1, pageIndex, pageSize,totalCount);
        } 

这是 PagedLis() 函数

 public PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount)
    {
        TotalCount = totalCount;
        TotalPages = TotalCount / pageSize;

        if (TotalCount % pageSize > 0)
            TotalPages++;

        this.PageSize = pageSize;
        this.PageIndex = pageIndex;
        this.AddRange(source);

    }

我想将此数据绑定到网格视图并且它具有分页功能。我可以绑定,它显示页码。但我的问题是,当我在网格视图中单击页码时,它总是只显示第一页。你有什么主意吗??

4

1 回答 1

0

我认为这些分页/排序/分组在使用第三方工具时会变得更容易。但是,请检查以下链接以使用 LINQ 在 c# 中进行分页/排序。

自定义分页

于 2012-12-10T06:54:46.957 回答