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

[Solved] Creating editable grid columns at runtime/code behind

1 Answer 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
R N
Top achievements
Rank 1
R N asked on 08 Feb 2010, 05:57 PM
Hi,
I am creating a grid at runtime (code behind) which could be either in view or edit mode depending on a user selection.
I have two ways to display the grid in view or edit mode.

For view mode:
Using the GridBoundColumn like below
                'if the field is always in view mode, no editing of data  
                column = New GridBoundColumn()  
                column.DataField = controlID 'eg "COL1"  
                column.UniqueName = controlID  
                grid.MasterTableView.Columns.Add(column)  
 

Or use GridTemplateColumn like below with ViewTemplate implementing ITemplate.
                    column = New GridTemplateColumn()  
                    column.ItemTemplate = New ViewTemplate(controlID)  
 


For edit mode:
Use GridTemplateColumn, set the columns in edit mode (true/false) using the PreRender event. ItemTemplate and EditItemTemplate would be used depending view/edit.

Or use only GridTemplateColumn with ItemTemplate with textbox controls for edit. And use GridBoundColumn for view mode. This way I don't need to loop through the columns in the prerender event to set the columns to edit mode. By using the GridTemplateColumn I would have the columns set to edit mode.

I am leaning towards the last option, I would like to know your opinion. Thanks!





1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Feb 2010, 03:05 PM
Hi,

I would suggest using the GridTemplateColumn only when you would want to use custom controls to  display data  in the normal and edit mode. If not then the GridBoundColumns will automatically create the textbox controls in the edit mode.

Hope this was useful.

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