Gridview表数据管理在不同视图中添加子头

时间:2016-02-01 06:00:11

标签: c# asp.net gridview

我想以不同的格式管理gridview的数据,比如添加子头

In this image data show of subheadnames's month wise

此数据的代码:

 var data = (from r in data
                          join texp in totalexplist on r.SancPropId equals texp.AllSanchAmtId into list2
                          from l2 in list2.DefaultIfEmpty()
                          select new
                          {
                              Id = r.Id,
                              FYear = r.FYear,
                              SancPropId = r.SancPropId,
                              ExpSubHeadId = r.ExpSubHeadId,
                              ExpSubHeadName = r.ExpSubHeadName,
                              ProposedAmount = r.ProposedAmount,
                              SanctionedAmount = r.SanctionedAmount,
                              MonthYear = l2 == null ? "" : l2.MnthYear,
                              Expenditure = l2 == null ? 0 : l2.Exp,
                              }).ToList();
  grd.DataSource = data;
  grd.DataBind();

但我想在下面的表格中显示这些数据

enter image description here

我已尝试使用此代码,但仍然添加到子标题

var monthwise = (from t in data
                    group t by new { t.MonthYear}
                        into grp
                        select new
                        {
                            grp.Key.MonthYear,
                            Data = grp.ToList()
                        }).ToList();
        var allColumns = monthwise.SelectMany(d => d.Data.Select(s => s.ExpSubHeadName)).Distinct().ToList();
        var datatable = new DataTable();
        datatable.Columns.Add(new DataColumn("Month"));
        allColumns.ForEach(c => datatable.Columns.Add(new DataColumn(c)));

有谁知道如何以这种形式管理网格?

0 个答案:

没有答案