views:

35

answers:

1

I'm building a GridView on the fly, and I'd like to pre-define the TemplateFields to be included ondemand. So, what I'd like to do is have a declarative file that defines how the different templates look for a specific column. Like:

<asp:TemplateField>
        <HeaderTemplate>
            this is a text column
        </HeaderTemplate>
        <ItemTemplate>
            data goes here
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox Text="databindhere" />
        </EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
        <HeaderTemplate>
            this is a bool column
        </HeaderTemplate>
        <ItemTemplate>
            if(true) "yes" else "no"
        </ItemTemplate>
        <EditItemTemplate>
            <asp:CheckBox Checked="databindme" />
        </EditItemTemplate>
</asp:TemplateField>

So, if my query had a text and two bool fields, I could push the appropriate TemplateFields in the the Columns property as needed. (I hope I'm making sense here)

So, how would I go about creating declarative files for the above definitions? And then, how would I reference those definitions programmatically?

A: 

Ok, what would work best is to subclass System.Web.UI.WebControls.TemplateField, but when I do that, I can't seem to use the object with the <%@ Register %> directive. If I could, I'd create a handful of UserControls with the new derivative, and then LoadControl() and Add() them to the Columns of my grid as needed.

Any ideas?

end-user