Hi,
I have been try to programmatically add templates to a WebDataGrid. This is described here:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1/CLR4.0/?page=WebDataGrid_Using_the_Template_Collection.html
I was successful with this. However, my next step was to set up some template control bindings...programmatically. The help documentation describes how to add template control bindings the Data Bindings Editor, here:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1/CLR4.0/?page=WebDataGrid_Template_Control_Bindings.html
The resulting ASP.NET markup looks something something like this:
...
</Columns> <Templates> ... <ig:ItemTemplate ID="WebDataGrid1Template2" runat="server" TemplateID="Template2"> <Template> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("name", "{0}") %>'></asp:TextBox> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("priority") %>'>HyperLink</asp:HyperLink> </Template> </ig:ItemTemplate> </Templates> </ig:WebDataGrid>
I can understand how to do this win markup However, I cannot see how I would add these template control bindings programmatically. Is there any help documentation on this? Are there any samples that demonstrate how to do this?
Hello Joel,
Thank you for posting in our forums.
I guess you want to achieve the below but in the code behind:
<ig:TemplateDataField Key="Message">
<ItemTemplate>
<asp:Image ID="Image1" ImageUrl='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Message") %>'
runat="server" />
</ItemTemplate>
<Header Text="Message" />
</ig:TemplateDataField>
It depend on the datasource that you are using , but is it DataTable for exmple the approach is the following:
public void InstantiateIn(Control container)
{
CheckBox chkBox = new CheckBox();
chkBox.ID = "TemplateCheckBox";
// Get the cell value from the DataItem
chkBox.Checked = (bool)((DataRowView)((TemplateContainer)container).DataItem)["BoolColumn"];
HyperLink link = new HyperLink();
link.ID = "TemplateHyperLink";
string dataValue = (string)((DataRowView)((TemplateContainer)container).DataItem)["Data"];
link.NavigateUrl = string.Format("http://www.google.bg/search?q={0}", dataValue);
link.Text = (string)((DataRowView)((TemplateContainer)container).DataItem)["Data"];
container.Controls.Add(link);
container.Controls.Add(chkBox);
}
Please refer to the sample code attached and let me know if you need further assistance.
Issue:
1) I have created a TemplateDataField with Textbox.
2) I am trying to findcontrol to get the value of textbox
3) It ways NULL, ItemTemplate is not retained at the POSTBACK.
Steps to reproduce:
1) Attached page has two grid (top) - dynamically created columns
2) Test1 button - print NULLs on findcontrol
2) 2nd grid is static columns through ASPX.
3) Test2 button - print VALUEs on findcontrol
Please help fixing the grid1/Test1 button and send me back the ASPX and ASPX.CS
Thanks in advance.