c#嵌套网格多次加载
我正在使用telerik radgrid。我正在以编程方式绑定网格。轴网加载正确,但嵌套轴网加载多次。(嵌套轴网中列数的倍数)。下面是我的代码c#嵌套网格多次加载,c#,telerik,radgrid,C#,Telerik,Radgrid,我正在使用telerik radgrid。我正在以编程方式绑定网格。轴网加载正确,但嵌套轴网加载多次。(嵌套轴网中列数的倍数)。下面是我的代码 GridTableView tableViewOrders = new GridTableView(grid); foreach (Application app in isParentApp) { DataTable tbl = new DataTable("nestedTable_" + app.AppId); objGridList
GridTableView tableViewOrders = new GridTableView(grid);
foreach (Application app in isParentApp)
{
DataTable tbl = new DataTable("nestedTable_" + app.AppId);
objGridList = GetGridList(app.AppId);
foreach (var nestedRow in objGridList)
{
GridRelationFields relationFields = new GridRelationFields();
relationFields.MasterKeyField = "AppId";
relationFields.DetailKeyField = "AppId";
tableViewOrders.ParentTableRelation.Add(relationFields);
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.DataField = nestedRow.ColName;
boundColumn.HeaderText = nestedRow.ColName;
tableViewOrders.Columns.Add(boundColumn);
grid.MasterTableView.DetailTables.Add(tableViewOrders);
tbl.Columns.Add(nestedRow.ColName);
}
foreach(var rows in totalRows)
{
DataRow nestedDtRow = tbl.NewRow();
nestedDtRow["AppId"] = app.AppId;
foreach (var nestedRecord in nestedRecords)
{
nestedDtRow[nestedRecord.colName] = nestedRecord.Data;
}
tbl.Rows.Add(nestedDtRow);
}
tableViewOrders.DataSource = tbl;
}
调试时,“tbl”只有一个表,但输出显示多个表
`
您正在为循环中的每一行反复添加列:
foreach (var nestedRow in objGridList)
{
}
您只需要在循环外执行一次。请参阅如何在循环外部添加列的答案 嗨,这个循环只添加一次列。。。“objGridList”实际上有一个列名列表。当我调试“tbl”时,它只有一个表。但是输出显示了许多表您正在为每一行添加一次,但是在我开始将行添加到DataTable之前,我已经关闭了循环您是否需要在tbl中为objGridList中的每一行添加一列?