常用分页查询绑定GridView的取数方式
1,通过linq:报表列表的查询,去除重复,一张报表在列表中显示一条数据;
------------DAL中
/// <summary> /// 查询所有的关于生产报表的填写数据情况 /// </summary> /// <param name="productionCase">查询条件:实体存储</param> /// <param name="pageIndex">页面号,如第一页</param> /// <param name="pageSize">每页数据显示条数</param> /// <param name="strOrderField">排序字段</param> /// <param name="isDesc">是否按降序排列</param> /// <returns>返回一个IList<ProductionCase>列表</returns> public IList<ProductionCase> GetProductBy(ProductionCase productionCase, int pageIndex, int pageSize, string strOrderField, bool isDesc) { StringBuilder sb = new StringBuilder(); List<ObjectParameter> paras = new List<ObjectParameter>(); sb.Append("1=1"); if (!String.IsNullOrEmpty(productionCase.DeptName)) { sb.Append(" and it.[DeptID] =@DeptID"); var param = new ObjectParameter("DeptID", productionCase.DeptID ); paras.Add(param); } return Context.ProductionCase.Where(sb.ToString(), paras.ToArray()).ToList(); }
-----------------页面 private void BindGVProduct(int type) { LRWorkflowEntities.ProductionCase productionCase = null; if (CurrentUser.ID == 1) { productionCase = new LRWorkflowEntities.ProductionCase() { }; } else { productionCase = new LRWorkflowEntities.ProductionCase() { DeptID = CurrentUser.SysDept.ID, }; } IList<LRWorkflowEntities.ProductionCase> iListProductionCase = bLLProduct.GetProductBy(productionCase, NvProduct.CurrentIndex,NvProduct.PageSize,NvProduct.OrderField,NvProduct.IsDesc); var ds = from c in iListProductionCase group c by new { c.DeptID, c.DeptName, c.ReportDate } into g select new { DeptID = g.Max(q => q.DeptID), DeptName = g.Max(q => q.DeptName), ReportDate = g.Max(q => q.ReportDate) }; if (type == 0) { NvProduct.RecordCount = ds.ToList().Count(); NvProduct.PageSize = (MainFrameHeight - Config.UserAdminHeaderHeight - Config.NormalLayoutHeaderHeight - Config.PageNavigatorHeight - Config.GridViewHeaderHeight) / Config.GridViewRowHeight; NvProduct.Bind(); } GVProduct.DataSource = ds.OrderByDescending(n => n.ReportDate).ThenByDescending(s => s.ReportDate).Skip((NvDuty.CurrentIndex - 1) * NvDuty.PageSize).Take(NvDuty.PageSize).ToList(); GVProduct.DataBind(); }
2,普通
3,linq
(未完待续)