2016-12-29 70 views
0

我正在使用telerik radgrid。我以編程方式綁定網格。網格正確加載,但嵌套網格多次加載(嵌套網格中的列數)。下面是我的代碼c#嵌套網格加載多次

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」只有一個表,但輸出顯示的多個表。

 ` 

回答

0

你一遍遍添加列的每一行中的這個循環:

foreach (var nestedRow in objGridList) 
{ 
} 

你只需要外循環一旦做到這一點。請參閱this回答如何添加循環外部的列。

+0

嗨,這個循環只添加一列......「objGridList」實際上有列名稱列表。 – user3064309

+0

當我調試「tbl」只有一個表。但輸出顯示很多表 – user3064309

+0

您正在爲每行添加一次 – CodingYoshi