custom *arbitrary* TemplateField definitions

Posted by end-user on Stack Overflow See other posts from Stack Overflow or by end-user
Published on 2010-03-16T14:29:23Z Indexed on 2010/03/23 19:03 UTC
Read the original article Hit count: 207

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?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about templatefield