I am populating a gridview with data from a stored procedure. I also have a checkbox template column that is not bound. I populate the grid just fine and then I check a checkbox and click a button to read the checkbox, but it always returns Checked = false.
I have set breakpoints so I know that the code is being executed.
Here is the code behind the button -
protected void btnUpdatePreferences_Click(object sender, EventArgs e)
{
if (gvwPreferences.Rows.Count >= 1)
{
foreach (GridViewRow row in gvwPreferences.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox subscribe = (CheckBox)row.FindControl("Checkbox1");
}
}
}
}
Any suggestions?
Thanks, Kevin.
.aspx file
<asp:TemplateField HeaderText="IsRejected">
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="chkIsRej
</ItemTemplate>
</asp:TemplateField>
.cs file
protected void chkIsRejected_CheckedChang
{
CheckBox chkReject = (CheckBox)sender;
//to get the grid view row where this checkbox is present
GridViewRow gvr = (GridViewRow)chkReject.Nam
if (chkReject.Checked)
{
//do any operations
}
}
if you follow this then you wnt need a button to check the checked property