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

RadGrid lose Headers

1 Answer 79 Views
This is a migrated thread and some comments may be shown as answers.
Patrick Weber
Top achievements
Rank 1
Patrick Weber asked on 19 May 2010, 07:33 AM
Hi there.

This is my first trip with RadControls. I've created an usercontrol, which shows a Grid. My datasource is a DataTable, wich is populated on NeedDataSource event. I have to dynamically generate all columns of DataTable at runtime, so my ASCX file is pretty poor:


Also i need to group data. Therefore, i add columnbound on codebehind. Here is the important part of NeedDataSource

            RadGrid1.DataSource = table;  
            RadGrid1.GroupingEnabled = true;  
            RadGrid1.AutoGenerateColumns = false;  
            GridBoundColumn boundcolumn;  
            foreach (DataColumn column in table.Columns)  
                if (column.ColumnName == "Name")  
                boundcolumn = new GridBoundColumn();  
                boundcolumn.DataField = column.ColumnName;  
                boundcolumn.HeaderText = column.ColumnName;  
            GridGroupByExpression expression = new GridGroupByExpression();  
            GridGroupByField groupbyfield = new GridGroupByField();  
            groupbyfield.FieldName = "Name";  
            groupbyfield.HeaderText = " ";  
            groupbyfield.HeaderValueSeparator = string.Empty;  
            groupbyfield.FormatString = "{0}";  
            groupbyfield = new GridGroupByField();  
            groupbyfield.FieldName = "Name";  
            RadGrid1.EnableViewState = true

All works fine and the output is really pretty. But if i collapse one group, all column headers will be lost. I've also implemented export to Excel and PDF. It generates a file, but there are much more columns and some values are System.Data.DataRowView. Maybe it's the same reason?

Please advise me. Thanks

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 25 May 2010, 01:45 PM
Hello Patrick,

I don't recommend that you create the columns on NeedDataSource but if you prefer to use this approach, you should modify your code as demonstrated in the attached demo.

The better way would be to create the grid programmatically on Page_Load or Page_Init. Please examine the following links for more information;
Programmatic creation
On PageInit
On PageLoad

Best regards,
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Asked by
Patrick Weber
Top achievements
Rank 1
Answers by
Telerik team
Share this question