Search code examples
asp.netgridviewuser-controlstemplatefield

Using a TemplateField inside a web user control


Is it possible to use a TemplateField (or any *Field from a GridView) inside a user control (ascx).

I have a complex TemplateField (item, edit, footer) that I would like to easily reuse.

Thanks.


Solution

  • As the question is worded, there is no way. What it sounds like you are doing (making the elements of a TemplateColumn reusable) then there are two ways that come to mind right off.

    One, put your User Control into the ItemTemplate/FooterTemlate of the TemplateColumn.

    Two, build the complex GridView Column as a standalone server control, which you can use in place of a TemplateColumn (or BoundColumn).