title: How to solve System.ArgumentOutOfRangeException exception?
body: <p>I have a grid with several data columns and a column with check boxes. There is a column called app Number which contains numbers. Now I want to <strong>select number in  the checked rows and put them into an array</strong>. How can I do it?             </p>
  
  <p>Here is the code I have done up to now.               </p>
  
  <pre><code>&lt;asp:GridView ID="gvAppeals" runat="server" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
      Width="665px" AutoGenerateColumns="False" OnSelectedIndexChanged="gvAppeals_SelectedIndexChanged1"
      AllowPaging="True" PageSize="10" OnPageIndexChanging="gvAppeals_PageIndexChanging" OnRowDataBound="gvAppeals_RowDataBound"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="App_no" HeaderText="APP NO"&gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
              &lt;ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="EMP_FULLNAME" HeaderText="FULL NAME"&gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
              &lt;ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="EMP_NIC_NO" HeaderText="NIC"&gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
              &lt;ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="EMP_BIRTHDAY" HeaderText="BIRTH DATE" DataFormatString="{0:yyyy-MM-dd}"&gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
              &lt;ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:TemplateField&gt;
              &lt;%--&lt;HeaderTemplate&gt;
                              &lt;asp:CheckBox ID="chkHeader" runat="server" AutoPostBack="true" /&gt;
                          &lt;/HeaderTemplate&gt;--%&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:CheckBox ID="chkSelect" runat="server" /&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
      &lt;FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /&gt;
      &lt;HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" /&gt;
      &lt;PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /&gt;
      &lt;RowStyle BackColor="White" ForeColor="Black" /&gt;
      &lt;SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#FEFCEB" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#AF0101" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#F6F0C0" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#7E0000" /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><strong>C# code</strong>              </p>
  
  <pre><code>protected void btnConfirm_Click(object sender, EventArgs e)
      {
          //DataSet ds = new DataSet();
          int[] numbers;
          numbers = new int[gvAppeals.Rows.Count];
          int noOfRowsChecked = 0;
  
          foreach (GridViewRow row in gvAppeals.Rows)
          {
              int rowIndex = row.RowIndex;
              CheckBox chkrow = (CheckBox)row.FindControl("chkSelect");
  
              if (chkrow.Checked == true)
              {
                  numbers[noOfRowsChecked] = Int32.Parse(gvAppeals.DataKeys[rowIndex]["App_no"].ToString());
                  noOfRowsChecked++;
              }
  
              //update the dept by checking the selected appeal numbers 
              if (noOfRowsChecked &gt; 0)
              {
                  for (int i = 0; i &lt; numbers.Length; i++)
                  {
                      int appNo = numbers[i];
                      dba.confirmAppeal(appNo);
                  }
              }
              else
              {
                  WebMsgBox.Show("Please select an application to confirm");
              }
          }
      }
  </code></pre>