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
530
Webdatagrid template data field
posted

I have a field I am creating a web image button (template data field), within the grid, which allows them to sign up for a class.  It will allow them to proceed to the next page if clicked.  I would like to be able to show a label instead of the button if the class is full.  Is this possible?  I would be getting the "toggle" item from the database (from within the datasource populating the grid).  Thanks in advance for your help.

Parents
  • 8160
    posted

    Hello bpabmeyer,

    you can handle InitializeRow event and populate templated column based on some condition. Use Item Template 


            <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px"
                AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                oninitializerow="WebDataGrid1_InitializeRow">
                <Columns>
                    <ig:BoundDataField DataFieldName="ProductID" Key="ProductID">
                        <Header Text="ProductID" />
                    </ig:BoundDataField>
                    <ig:BoundDataField DataFieldName="ProductName" Key="ProductName">
                        <Header Text="ProductName" />
                    </ig:BoundDataField>
                    <ig:TemplateDataField Key="TemplateField_0">
                        <Header Text="TemplateField_0" />
                    </ig:TemplateDataField>
                </Columns>
            </ig:WebDataGrid>



       protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
        {
            //check some condition
            if (e.Row.Items[1].Text == "Chef Anton's Cajun Seasoning")
            {
                e.Row.Items[2].Template = new CustomItemTemplate();
            }
            else
            {
                e.Row.Items[2].Text = "No avaiable classes";
            }
        }
    
        private class CustomItemTemplate : ITemplate
        {
            #region ITemplate Members
    
            public void InstantiateIn(Control container)
            {
    
                LinkButton edit = new LinkButton();
                edit.CssClass = "LinkButton";
                edit.Text = "Edit";
                edit.OnClientClick = "return editRow()";
    
                LinkButton delete = new LinkButton();
                delete.CssClass = "LinkButton";
                delete.Text = "Delete";
                delete.OnClientClick = "return deleteRow()";
    
                container.Controls.Add(edit);
                container.Controls.Add(delete);
            }
    
            #endregion
        }
    



    I hope this helps
Reply Children
No Data