Hi,
I have a statically declared but dynamically created Grid. The columns and their datatypes are not known until runtime. So, I create regular GridBoundColumn at runtime. Some columns are numeric and some columns need to be dropdowns, checkboxes etc. I have all the code to create the boundcolumns and display it and edit it. I guess I need to replace the auto-generated column editors in CreateColumnEditor event. Is there a sample I can base my code upon? Because the following code throws me an error "Object reference not set to an instance of an object".
Here is my code to create the columns.
And here my code for CreateColumnEditor event:
Please help.
Babu.
I have a statically declared but dynamically created Grid. The columns and their datatypes are not known until runtime. So, I create regular GridBoundColumn at runtime. Some columns are numeric and some columns need to be dropdowns, checkboxes etc. I have all the code to create the boundcolumns and display it and edit it. I guess I need to replace the auto-generated column editors in CreateColumnEditor event. Is there a sample I can base my code upon? Because the following code throws me an error "Object reference not set to an instance of an object".
Here is my code to create the columns.
| protected void DefineColumnsForGrid(RadGrid grid, DataTable tbl) |
| { |
| grid.Columns.Clear(); |
| FormsIdentity user = (FormsIdentity)HttpContext.Current.User.Identity; |
| if (user == null) |
| return; |
| for (int i = 0; i < tbl.Columns.Count; i++) |
| { |
| GridBoundColumn col = new GridBoundColumn(); |
| col.HeaderText = tbl.Columns[i].ColumnName; |
| col.DataField = tbl.Columns[i].ColumnName; |
| col.UniqueName = tbl.Columns[i].ColumnName; |
| col.DataType = tbl.Columns[i].DataType; |
| col.ReadOnly = true; // isEditable |
| grid.Columns.Add(col); |
| } |
| } |
And here my code for CreateColumnEditor event:
| protected void rgForecast_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e) |
| { |
| if (e.Column is GridBoundColumn) |
| { |
| if ((e.Column as GridBoundColumn).DataType == typeof(System.Decimal)) |
| { |
| (e.Column as GridBoundColumn).ColumnEditorID = (e.Column as GridBoundColumn).UniqueName + "1"; |
| e.ColumnEditor = new GridNumericColumnEditor(new GridNumericColumn()); |
| } |
| } |
| } |
Please help.
Babu.