Can't access value of checkbox on button click c#
<p>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.</p>

<p>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.</p>

<p>I am looking for them with </p>

<pre><code>foreach (GridViewRow gvr in GridView1.Rows)
{
   CheckBox cb = (CheckBox)gvr.FindControl("check" + gvr.Cells[2].Text);
   ...
}
</code></pre>

<p>I have a hunch they might be getting destroyed on postback but I'm not sure how to make sure this doesnt happen.</p>

<p>Everything in my Page_Load method is contained in a if(!IsPostBack) statement.</p>

<p>some asked for my page_load:</p>

<p><code>
foreach (GridViewRow gvr in GridView1.Rows)
                {</p>

<pre><code>                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);

            }
</code></pre>

<p></code></p>

<p>I think is the relevant part.</p>
