I add checkboxes
on RowDataBound
in a Gridview
:
for (int i = 1; i < e.Row.Cells.Count; i++)
{
CheckBox cb = new CheckBox();
cb.ID = "Checkbox" + i.ToString();
if (e.Row.Cells[i].Text == "true") cb.Checked = true; else cb.Checked = false;
e.Row.Cells[i].Controls.Add(cb);
}
On Button click I want to read the state of the checkboxes:
foreach (GridViewRow gvr in GV.Rows)
{
for (int i = 1; i < GV.HeaderRow.Cells.Count; i++)
{
CheckBox cb = gvr.FindControl("Checkbox" + i.ToString()) as CheckBox;
if (cb.Checked == true)
{
//To something
}
}
}
This code works with Framework 4 (controls are found) but not with Framework 4.5.2 (controls are empty). How can I fix this? Thanks