I am binding data to a gridview in Page_Load and then in the same Page_Load I am adding a column of check boxes which are not part of the databinding.
Then when a button is pressed I want to check to see if any of the boxes are checked. However, when I look for the checkboxes in my button_click method the checkboxes seem to have disappeared entirely.
I am looking for them with
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("check" + gvr.Cells[2].Text);
...
}
I have a hunch they might be getting destroyed on postback but I'm not sure how to make sure this doesnt happen.
Everything in my Page_Load method is contained in a if(!IsPostBack) statement.
some asked for my page_load:
foreach (GridViewRow gvr in GridView1.Rows)
{
TableCell tc = new TableCell();
CheckBox cb = new CheckBox();
cb.ID = "check" + gvr.Cells[2].Text;
tc.Controls.AddAt(0, cb);
gvr.Cells.AddAt(0, tc);
}
I think is the relevant part.
Page_Loadevent please.