Hi
We're creating a grid dynamically and are running into some issues. Both the columns and datatypes are defined in the database.
The grid consists of 1 GridBoundColumn and multiple GridTemplateColumns hence the radgrid is defined entirely in the code behind (in the Page_Init event). Additionally, the rows of the datasource (based on a DataTable) we're using is built up dynamically in the .NET code as rows can have any number of columns. This is populated in the RadGrid_NeedDataSource event.
We are using ASP.NET_AJAX_2009_1_402 and are creating the templates with classes implementing the IBindableTemplate interface.
On viewing the page the first time, the data displays in the grid in the correct number of columns (with correct column headings). So far so good.
However, the problems we're facing are:
1. Even though AllowSorting is set to True, the GridTemplateColumn headers are not clickable (the GridBoundColumn sorts fine). How do we get the GridTemplateColumns to be sortable as well?
2. One of the static controls on the page is a check box control that controls the visibility of certain columns in the grid. The user can choose to see those columns at run time. The only way I could get this to work is to set the column.Visible property (to true or false depending on the state of the checkbox) in the Page_Load() event and call grid.Rebind(). This results in a rebind for every post back. Is this the correct way to do this?
3. Clicking the 'Insert a new entry' link brings up the Insert form fine (with default values as programmed) but on clicking 'Insert', it crashes with an 'unable to cast to null' error. The specific control we're using for our testing is the RadDatePicker .. the crash is caused when attempting a cast a Null to a RadDatePicker in the DataBind event of the DateTemplate (see code below). The
insertionObject.GetPropertyValue(columnName) I'm attempting to use is null - which is confirmed by the Utils.Log debugging that I'm doing.
| public void BindData(object sender, EventArgs e) |
| { |
| RadDatePicker radDatePicker = (RadDatePicker)sender; |
| if (radDatePicker.NamingContainer is GridEditFormInsertItem) |
| { |
| // Insert mode |
| GridEditFormInsertItem container = (GridEditFormInsertItem)radDatePicker.NamingContainer; |
| GridInsertionObject insertionObject = (GridInsertionObject)container.DataItem; |
| Utils.Log("Date BindData=" + columnName + ": Propval=" + insertionObject.GetPropertyValue(columnName).ToString()); |
| radDatePicker.SelectedDate = ((RadDatePicker)insertionObject.GetPropertyValue(columnName)).SelectedDate; |
| } |
| else |
| { |
| // Edit mode |
| GridEditFormItem container = (GridEditFormItem)radDatePicker.NamingContainer; |
| radDatePicker.SelectedDate = Utils.StringToDateTime(((DataRowView)container.DataItem)[columnName].ToString()); |
| } |
| } |
4. Clicking the Edit link merely does a page refresh and does not display the Edit form.
5. When exporting the data to Excel or PDF, all the column headings appear fine. However, only the data in the GridBoundColumn appears (i.e. data for the GridTemplateColumns is blank).
6. In your example on http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html, your templates implement ITemplate (and not IBindableTemplate). I could not find a way to use the ITemplate as in your example. I take it I need IBindableTemplate for this?
Do you have a working example of a grid that is dynamically created using templates like the problem we're facing? That would be a great reference.
Thanks