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
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(); } }