I have a grid that is defined statically, with columns created dynamically. I followed your documentation on how to do this, creating columns in Page_Load, but when I do that, the columns disappear when sorting.
The grid is ajaxed to update itself via a RadAjaxManager. If I try to add the columns on Page_Init, i get the following javascript error:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Cannot find column LocationName.
NOTE: "LocationName" is a valid name of a field in my datasource.
Here's the full skinny. I have a page opened in a RadWindow. That page loads a user control in Page_Load that has my grid. The user control does some grid setup in Page_Init, then adds the columns in Page_Load (an example of adding a column):
Telerik.Web.UI.GridBoundColumn gridCol = new Telerik.Web.UI.GridBoundColumn();
grid.MasterTableView.Columns.Add(gridCol);
gridCol.HeaderText = "Location";
gridCol.UniqueName = "LocationName";
gridCol.DataField = "LocationName";
if (grid.AllowSorting) gridCol.SortExpression = "LocationName";
gridCol.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
gridCol.ItemStyle.Width = Unit.Percentage(25);
gridCol.HeaderStyle.HorizontalAlign = HorizontalAlign.Left;
gridCol.HeaderStyle.Width = Unit.Percentage(25);
I'm using NeedDataSource. When I click the "LocationName" column to sort (or any column, for that matter), the entire grid goes away. If I do the exact same column adding in Page_Init, the javascript error I posted above occurs. Any help?