Design Time vs Run Time DataGrid

G

Guest

Is it possible to define the <ItemTemplate> and <EditItemTemplate> in
DataGrid programitically at run-time?

The sample definition is as follows:

//===============================================
<asp:TemplateColumn HeaderText="TestColumnLabel">

<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.str_pblock") %>'>
</asp:Label>
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.str_pblock") %>'>
</asp:TextBox>
</EditItemTemplate>

</asp:TemplateColumn>
//===============================================
 
K

Karl Seguin

Rk:
Absolutely, take a look at the Page.LoadTemplate() function. It behaves a
lot like the Page.LoadControl, but instead of returning an instance of
Control it returns an instance of Itemplate, which can be assigned to the
datagrid's ItemTemplate and/or EditTemplate property. Other than that it
works a lot like a user control.

There are all types of resource (google search for Page.LoadTemplate might
be your best bet):
http://msdn.microsoft.com/library/d...umnsdynamicallyindatalistwebservercontrol.asp
http://www.aspdotnetheaven.com/Code/Jan2003/DynamicTemplate.asp

I think instead of using Container.DataItem you simply use Container

Happy Hunting
Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top