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
15
CheckBox column - problems getting check state
posted

Hello,

I have a Template field defined for my WebDataGrid containing a check box.  

The version of NetAdvantage that I ran is Infragistics45.Web.v19.2.

<ig:WebDataGrid ID="grid" EnableDataViewState="true" EnableViewState="true" AutoGenerateColumns="false" runat="server" Height="350px" Width="400px">
<Columns>
    <ig:TemplateDataField Key="include" Width="50px">
        <Header Text="CHK" />
            <ItemTemplate>
                <asp:CheckBox ID="cbItem" runat="server" Checked="true"></asp:CheckBox>
            </ItemTemplate>
    </ig:TemplateDataField>
</Columns>
</ig:WebDataGrid>


<p>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</p>

I click a button to process any changes made to the grid - I have unchecked some of the rows.

protected void Button1_Click(object sender, EventArgs e)
{
    GridRecordCollection gridRecords = grid.Rows;
    foreach (GridRecord record in gridRecords)
    {
        CheckBox cbItem= (CheckBox)record.Items[0].FindControl("cbItem");
        if (cbItem.Checked) // => cbItem is null
        {
        }
    }

}

Please could anyone let me know what I am doing wrong and it all should be so simple

Parents
No Data
Reply
  • 2155
    Offline posted

    Hello,

    You should be able to reference your CheckBox instances by calling WebDataGrid.EnsureTemplates() method at PageLoad like below.

            protected void Page_Load(object sender, EventArgs e)
            {
    .....
                if (IsPostBack)
                {
                    grid.EnsureTemplates();
                }
            }

Children
No Data