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

RadGrid headers disappearing on select command

3 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zachary
Top achievements
Rank 1
Zachary asked on 18 Mar 2011, 12:16 AM
I have a RadGrid that is being configured dynamically at run time. The purpose is create a custom grid based on an arbitrary sql query. I'm adding a gridbuttoncolumn at runtime that has a select command. When this button is clicked, all the select links disappear and the column headers disappear as well. Any thoughts on what this issue may be?

3 Answers, 1 is accepted

Sort by
0
Zachary
Top achievements
Rank 1
answered on 18 Mar 2011, 12:37 AM
As a follow up, my Select button is not firing off  the selectedindexchanged. The itemcommand event is firing, but the CommandName property is an empty string.

here is the code I'm using to set up my grid:

RadAjaxManager1.AjaxSettings.AddAjaxSetting(DropDownList1, RadGrid1);
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadGrid1);
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, Label1);
Query q = query;
 
RadGrid1.MasterTableView.Columns.Clear();
RadGrid1.MasterTableView.DataKeyNames = GetPKArray(q.PrimaryKeys);
 
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
RadGrid1.AutoGenerateColumns = false;
 
GridButtonColumn col = new GridButtonColumn();
col.CommandName = "Select";
col.Text = "Select";
RadGrid1.MasterTableView.Columns.Add(col);
 
foreach (QueryColumns qCol in q.QueryColumns)
{
    GridBoundColumn bCol = new GridBoundColumn();
    bCol.HeaderText = qCol.ColumnName.Replace("[", "").Replace("]", "");
    bCol.DataField = qCol.ColumnName;
 
    RadGrid1.MasterTableView.Columns.Add(bCol);
}

I have to run this code everytime the grid is rebound or I get the Columns full of "System.Data.DataRowView"
0
Zachary
Top achievements
Rank 1
answered on 18 Mar 2011, 12:50 AM
So it appears I have to run Rebind() on every postback. Can someone telerik confirm if this is the intended behavior for this control?
0
Princy
Top achievements
Rank 2
answered on 18 Mar 2011, 10:26 AM
Hello Zachary,

If you have declared RadGrid in the ASPX page and use the Page_Load event handler to adding columns to grid, then the columns should be added to the corresponding collection first, before the values for their properties are set.

C#:
GridButtonColumn col = new GridButtonColumn();
RadGrid1.MasterTableView.Columns.Add(col);
col.CommandName = "Select";
col.Text = "Select";

Please check out the following documentation.
Programmatic creation

Thanks,
Princy.
Tags
Grid
Asked by
Zachary
Top achievements
Rank 1
Answers by
Zachary
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or