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

RadGrid lose Headers

1 Answer 90 Views
Grid
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:

<TELERIK:RADGRID ID="RadGrid1" RUNAT="server" ALLOWSORTING="true">  
</TELERIK:RADGRID> 

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")  
                {  
                    continue;  
                }  
                boundcolumn = new GridBoundColumn();  
                boundcolumn.DataField = column.ColumnName;  
 
                boundcolumn.HeaderText = column.ColumnName;  
                  
                RadGrid1.MasterTableView.Columns.Add(boundcolumn);  
 
            }  
 
 
            GridGroupByExpression expression = new GridGroupByExpression();  
            GridGroupByField groupbyfield = new GridGroupByField();  
            groupbyfield.FieldName = "Name";  
            groupbyfield.HeaderText = " ";  
            groupbyfield.HeaderValueSeparator = string.Empty;  
            groupbyfield.FormatString = "{0}";  
            expression.SelectFields.Add(groupbyfield);  
 
            groupbyfield = new GridGroupByField();  
            groupbyfield.FieldName = "Name";  
            expression.GroupByFields.Add(groupbyfield);  
            RadGrid1.MasterTableView.GroupByExpressions.Add(expression);  
            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
0
Daniel
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,
Daniel
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.
Tags
Grid
Asked by
Patrick Weber
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or