Hi,
I have a hierarchical grid defined where I am programattically binding the detail tables. I am also generating some dynamic columns at runtime depending upon the user's input and adding them to the master as well as the detail tables.
Everything seems fine barring the issue of column names of the dynamic columns getting disappeared as soon as I expand the grid. The values still remain intact and so does the dataformatstring.
I see some discussions around this issue in the following thread but the suggestions provided does not work for me.
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-runtime-columns.aspx
Here's my code snippet
I have a hierarchical grid defined where I am programattically binding the detail tables. I am also generating some dynamic columns at runtime depending upon the user's input and adding them to the master as well as the detail tables.
Everything seems fine barring the issue of column names of the dynamic columns getting disappeared as soon as I expand the grid. The values still remain intact and so does the dataformatstring.
I see some discussions around this issue in the following thread but the suggestions provided does not work for me.
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-runtime-columns.aspx
Here's my code snippet
| <telerik:RadGrid ID="rgScenario" runat="server" Width="100%" Skin="Custom" EnableEmbeddedSkins="false" |
| AutoGenerateColumns="false" AllowSorting="false" AllowPaging="false" AllowFilteringByColumn="false" OnDetailTableDataBind="rgScenario_DetailTableDataBind" OnNeedDataSource="rgScenario_NeedDataSource"> |
| <MasterTableView DataKeyNames="xxxx" runat="server" EnableColumnsViewState="true"> |
| <DetailTables> |
| <telerik:GridTableView DataKeyNames="yyyy" runat="server" Name="Detail1" Width="100%" EnableColumnsViewState="true" > |
| <DetailTables> |
| <telerik:GridTableView DataKeyNames="zzzz" runat="server" Name="Detail2" Width="100%" EnableColumnsViewState="true"> |
| <Columns> |
| <telerik:GridBoundColumn HeaderText="Area" DataField="Area" UniqueName="Area"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Days" DataField="Days" UniqueName="Days"></telerik:GridBoundColumn> |
| </Columns> |
| </telerik:GridTableView> |
| </DetailTables> |
| <Columns> |
| <telerik:GridBoundColumn HeaderText="Start Area" DataField="StartAreaName" UniqueName="StartAreaName"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="End Area" DataField="EndAreaName" UniqueName="EndAreaName"></telerik:GridBoundColumn> |
| </Columns> |
| </telerik:GridTableView> |
| </DetailTables> |
| <Columns> |
| <telerik:GridBoundColumn HeaderText="Vessel" DataField="VesselType" UniqueName="Vessel"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Days" DataField="TotalVoyageDaysNum" UniqueName="TotalVoyageDaysNum"></telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| public partial class ComparisonReport : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| try |
| { |
| if (!IsPostBack) |
| { |
| //Populate data into an IList say ParentIList |
| ShowHideRiskColumns(input); |
| } |
| rgScenario.DataSource = ParentIList; |
| } |
| } |
| catch(Exception ex) |
| { |
| } |
| } |
| private void ShowHideRiskColumns(string input) |
| { |
| GridBoundColumn parentDynamicColumn = new GridBoundColumn(); |
| parentDynamicColumn.HeaderText = "Some text"; |
| parentDynamicColumn.UniqueName = "Some text"; |
| parentDynamicColumn.DataFormatString = "{0:#,###.##}"; |
| GridBoundColumn childDynamicColumn= new GridBoundColumn(); |
| childDynamicColumn.HeaderText = "Some text"; |
| childDynamicColumn.UniqueName = "Some text"; |
| GridBoundColumn subChildDynamicColumn = new GridBoundColumn(); |
| subChildDynamicColumn.HeaderText = "Some text"; |
| subChildDynamicColumn.UniqueName = "Some text"; |
| rgScenario.MasterTableView.Columns.Add(parentDynamicColumn); |
| rgScenario.MasterTableView.DetailTables[0].Columns.Add(childDynamicColumn); |
| rgScenario.MasterTableView.DetailTables[0].DetailTables[0].Columns.Add(subChildDynamicColumn); |
| switch(input) |
| { |
| case 1: |
| //Set the datafield according to the input |
| break; |
| case 2: |
| //Set the datafield according to the input |
| break; |
| } |
| } |
| protected void rgScenario_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| if (!e.IsFromDetailTable) |
| { |
| rgScenario.DataSource = iList; |
| } |
| } |
| protected void rgScenario_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) |
| { |
| GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; |
| switch (e.DetailTableView.Name) |
| { |
| case "Detail1": |
| { |
| e.DetailTableView.DataSource = detailList1; |
| break; |
| } |
| case "Detail2": |
| { |
| e.DetailTableView.DataSource = detailList2; |
| break; |
| } |
| } |
| } |
| } |