Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
How to add template control bindings programmatically?
posted

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?

 

 

 

Parents
No Data
Reply
  • 19693
    Verified Answer
    posted

    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.

    DynamicWDG.zip
Children