title: CheckBox Checked state inside gridview
body: <p>I have a simple gridview</p>
  
  <pre><code>            &lt;asp:GridView ID="GridView1" runat="server" DataKeyNames="OriginatorID" AutoGenerateColumns="False"
              AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="5"
              OnPreRender="GridView1_PreRender"&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:CheckBox ID="CheckBox1" runat="server" /&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:BoundField DataField="Originator" HeaderText="Originator" /&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>I'm calling following code inside <code>GridView1_PageIndexChanging</code> event</p>
  
  <pre><code>        foreach (GridViewRow item in GridView1.Rows)
          {
              try
              {
                  if (item.RowType == DataControlRowType.DataRow)
                  {
                      CheckBox chk = (CheckBox)(item.Cells[0].FindControl("CheckBox1"));
  
                      // chk.checked will access the checkbox state on button click event
                      if (chk.Checked)
                      {
                          //code if checked
                      }
                      else
                      {
  
                      }
                  }
  
              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }
  </code></pre>
  
  <p>problem if I select a checkbox and select the next page on gridview it never execute the code inside </p>
  
  <pre><code> if (chk.Checked)
  </code></pre>
  
  <p>even though I have checked the chekBoxes it's not get their state as checked.</p>
  
  <p>why could this happen?</p>