views:

44

answers:

2

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.

A: 

GridView is a bit top-heavy for a user control - you could create a custom GridView in a separate control library and simply reuse it that way.

IrishChieftain
+1  A: 

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

Stephen Wrighton
I am currently using your first solution but I am looking for a single user control replacing the whole TemplateField. So it seems it is not possible.I will have a look to your second solution. I have never done server control yet.Thanks.
Sylvain