Hi
I've followed this example and the documentation here to create a grid with 2 rows in the header for just some of the columns. I've declared the grid control in the .aspx control, and declared the mixture of normal bound columns and template columns in the Page_Init function of the code behind.
It displays fine, but when I do a postback (eg sort) then it adds more columns to the grid. I've tried checking for IsPostback, but that just makes the template column contents disappear. What am I missing?
Here is the .aspx page:
Code behind excerpt:
Kind Regards,
Jeremy
I've followed this example and the documentation here to create a grid with 2 rows in the header for just some of the columns. I've declared the grid control in the .aspx control, and declared the mixture of normal bound columns and template columns in the Page_Init function of the code behind.
It displays fine, but when I do a postback (eg sort) then it adds more columns to the grid. I've tried checking for IsPostback, but that just makes the template column contents disappear. What am I missing?
Here is the .aspx page:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowSorting="true" Skin="Vista"> <MasterTableView DataKeyNames="HOLE_ID, HOLE_SORT"> <HeaderStyle HorizontalAlign="Center" /> <ItemStyle HorizontalAlign="Center" /> <AlternatingItemStyle HorizontalAlign="Center" /> <NoRecordsTemplate> <div style="width:100%; text-align:center; height:21px; padding:4px 4px 4px 10px;"> <asp:Label ID="lblNoRecords" runat="server" Text="No data exists for this Hole."></asp:Label> </div> </NoRecordsTemplate> </MasterTableView> <ClientSettings> <Scrolling AllowScroll="true" /> </ClientSettings></telerik:RadGrid>Code behind excerpt:
Private colHeaderGroupList as List(of String) = GetColumnHeaderGroups()Private colHeaderList as List(of MyColumnData) = GetColumnHeaderData()Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init If Page.IsPostBack = False Then LoadColumns() End IfEnd SubPrivate Sub LoadColumns() 'clear columns RadGrid1.MasterTableView.Columns.Clear() 'add standard column Dim col1 As GridBoundColumn = New GridBoundColumn() RadGrid1.MasterTableView.Columns.Add(col1) With col1 .DataField = "HOLE_NO" .HeaderText = "Hole" .SortExpression = "HOLE_SORT" End With 'add elements as template columns to use double row headers For Each colHeader As String In colHeaderGroupList 'add column to grid Dim templateCol As GridTemplateColumn = New GridTemplateColumn() RadGrid1.MasterTableView.Columns.Add(templateCol) 'get just the columns for this group Dim thisGroup as List(of MyColumnData) = (From x in colHeaderList Where x.Group = colHeader Select x).ToList() 'create templates for column templateCol.HeaderTemplate = New MyDynamicHeaderTemplate(thisGroup) templateCol.ItemTemplate = New MyDynamicItemTemplate(thisGroup) NextEnd SubPrivate Class MyDynamicHeaderTemplate...End ClassPrivate Class MyDynamicItemTemplate...End ClassKind Regards,
Jeremy