我想以不同的格式管理gridview的数据,比如添加子头
此数据的代码:
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();
但我想在下面的表格中显示这些数据
我已尝试使用此代码,但仍然添加到子标题
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)));
有谁知道如何以这种形式管理网格?