Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more: (untagged)
Currently, I have something like this:

<br /><asp:DataGrid><br />  <asp:TemplateColumn><br />    <ItemTemplate><br />      //some markup that tells us what controls to draw for ItemTemplate<br />    </ItemTemplate><br />    <EditItemTemplate><br />      //same markup as in ItemTemplate which should not be duplicated<br />    </EditItemTemplate><br />  </asp:TemplateColumn><br /></asp:DataGrid><br />


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.
Posted

1 solution

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 to ItemTemplate property ... here is the code:

TemplateField colmun = this.GridView1.Columns[0] as TemplateField;<br />colmun.EditItemTemplate = colmun.ItemTemplate;


 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900