I tracked down a problem after a few hours of digging ...
I am creating columns in the Page_Load event for a RadGrid. I only add the columns if NOT a PostBack event. Basically I had something like this:
if (!Page.IsPostBack)
{
// Add each column to the DataTable
for (int col = 0; col < kview.GridColumns.Count; col++)
{
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
boundColumn.UniqueName = "Name" + col;
boundColumn.DataField = "Data" + col;
boundColumn.HeaderText = "Header" + col;
// NOTE: I had the .Add AFTER setting the properties
this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
}
}
The problem was any postback cleared the column names. Then I found the article
http://www.telerik.com/help/aspnet/grid/grdprogrammaticcreation.html
which said to set the properties AFTER adding the column. So I changed it to this:
if (!Page.IsPostBack)
{
// Add each column to the DataTable
for (int col = 0; col < kview.GridColumns.Count; col++)
{
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
// NOTE: Now I add the column right away
this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.UniqueName = "Name" + col;
boundColumn.DataField = "Data" + col;
boundColumn.HeaderText = "Header" + col;
}
}
This worked (postbacks now keep the column names)?!?!?
Is this a known bug in the grid control. Even though the web page I found said to do it like this, this seems like a very weird restriction. There does not seem to be any sense to it.
I am creating columns in the Page_Load event for a RadGrid. I only add the columns if NOT a PostBack event. Basically I had something like this:
if (!Page.IsPostBack)
{
// Add each column to the DataTable
for (int col = 0; col < kview.GridColumns.Count; col++)
{
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
boundColumn.UniqueName = "Name" + col;
boundColumn.DataField = "Data" + col;
boundColumn.HeaderText = "Header" + col;
// NOTE: I had the .Add AFTER setting the properties
this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
}
}
The problem was any postback cleared the column names. Then I found the article
http://www.telerik.com/help/aspnet/grid/grdprogrammaticcreation.html
which said to set the properties AFTER adding the column. So I changed it to this:
if (!Page.IsPostBack)
{
// Add each column to the DataTable
for (int col = 0; col < kview.GridColumns.Count; col++)
{
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
// NOTE: Now I add the column right away
this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.UniqueName = "Name" + col;
boundColumn.DataField = "Data" + col;
boundColumn.HeaderText = "Header" + col;
}
}
This worked (postbacks now keep the column names)?!?!?
Is this a known bug in the grid control. Even though the web page I found said to do it like this, this seems like a very weird restriction. There does not seem to be any sense to it.