This is a migrated thread and some comments may be shown as answers.

sorted column headers disappear after sort

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peggy
Top achievements
Rank 1
Peggy asked on 20 Mar 2009, 07:29 PM
I have 2 grids on my page and I add the columns to the grids programmatically. When I test, everything appears fine on initial view, but when I sort, the column headers disappear. The first column is set to not allow a header and not allow a sort, but additional columns do allow this. Any hints on why this may be happening and what I can do to solve it?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Mar 2009, 05:37 AM
Hi Peggy,

Where are you adding the columns? Try adding the Grid columns in the PageLoad event as shown in the following help article.
Programmatic creation

Also consider sending your entire code behind.

Thanks
Shinu

0
Peggy
Top achievements
Rank 1
answered on 23 Mar 2009, 02:12 PM
I abandoned that routine as I could not figure it out; I was calling from the load function and I called this function:
        private void AddGridColumns(RadGrid gridForData, DataTable gridTable)  
        {  
            for (int i = 0; i < gridTable.Columns.Count; i++)  
            {  
                if (i == 0)  
                {  
                    Telerik.Web.UI.GridBoundColumn gbc_data = new Telerik.Web.UI.GridBoundColumn();  
                    gbc_data.AllowSorting = true;  
                    gbc_data.AllowFiltering = false;  
                    gbc_data.DataField = gridTable.Columns[i].ColumnName;  
                    gbc_data.HeaderText = "";  
                    gbc_data.SortExpression = gridTable.Columns[i].ColumnName;  
                    gbc_data.Resizable = false;  
                    gbc_data.ItemStyle.Width = Unit.Point(cellWidth);  
                    gridForData.MasterTableView.Columns.Add(gbc_data);  
                }  
                else 
                {  
                    Telerik.Web.UI.GridBoundColumn gbc_data = new Telerik.Web.UI.GridBoundColumn();  
                    gbc_data.AllowFiltering = false;  
                    gbc_data.AllowSorting = true;  
                    gbc_data.DataField = gridTable.Columns[i].ColumnName;  
                    gbc_data.HeaderText = gridTable.Columns[i].ColumnName;  
                    gbc_data.Resizable = true;  
                    gbc_data.ShowSortIcon = true;  
                    gbc_data.SortExpression = gridTable.Columns[i].ColumnName;  
                    gbc_data.ItemStyle.HorizontalAlign = HorizontalAlign.Right;  
                    gbc_data.HeaderButtonType = GridHeaderButtonType.LinkButton;  
                    gbc_data.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;  
                    gridForData.MasterTableView.Columns.Add(gbc_data);  
                }  
            }  
 
        } 
Now I am using the pre_render event to change the first column's display as that was what I wanted to achieve by adding my columns programmatically.
Tags
Grid
Asked by
Peggy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Peggy
Top achievements
Rank 1
Share this question
or