How to make DataGrid TemplateColumn ItemTemplate and EditItemTemplate the same without duplicating code?
-
Currently, I have something like this:
asp:DataGrid
asp:TemplateColumn
<ItemTemplate>
//some markup that tells us what controls to draw for ItemTemplate
</ItemTemplate>
<EditItemTemplate>
//same markup as in ItemTemplate which should not be duplicated
</EditItemTemplate>
</asp:TemplateColumn>
</asp:DataGrid>I was wondering if there was a way (either behind the scenes in C#) or in the markup itself, to make it so that we don't have to duplicate the markup. There was a thread I found for the FormView control, where we could set FormView.EditItemTemplate = FormView.ItemTemplate, but unfortunately, this is not available for the DataGrid TemplateColumn type.
-
Currently, I have something like this:
asp:DataGrid
asp:TemplateColumn
<ItemTemplate>
//some markup that tells us what controls to draw for ItemTemplate
</ItemTemplate>
<EditItemTemplate>
//same markup as in ItemTemplate which should not be duplicated
</EditItemTemplate>
</asp:TemplateColumn>
</asp:DataGrid>I was wondering if there was a way (either behind the scenes in C#) or in the markup itself, to make it so that we don't have to duplicate the markup. There was a thread I found for the FormView control, where we could set FormView.EditItemTemplate = FormView.ItemTemplate, but unfortunately, this is not available for the DataGrid TemplateColumn type.
Greetings, I think the thread you read already gave you the correct way ... its only a matter of casting the template column correctly then set the
EditItemTemplate
property toItemTemplate
property ... here is the code:TemplateField colmun = this.GridView1.Columns[0] as TemplateField;
colmun.EditItemTemplate = colmun.ItemTemplate;Sincerely Samer Abu Rabie Note: Please remember to rate this post to help others whom reading it.
-
Greetings, I think the thread you read already gave you the correct way ... its only a matter of casting the template column correctly then set the
EditItemTemplate
property toItemTemplate
property ... here is the code:TemplateField colmun = this.GridView1.Columns[0] as TemplateField;
colmun.EditItemTemplate = colmun.ItemTemplate;Sincerely Samer Abu Rabie Note: Please remember to rate this post to help others whom reading it.