title: Index out of range exception while deleting row from GridView
body: <p>I am getting error like </p>
  
  <blockquote>
    <p>"Index was out of range. Must be non-negative and less than the size
    of the collection"</p>
  </blockquote>
  
  <p>when trying to delete row of gridview. My aspx.cs code is below:   </p>
  
  <pre><code>protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {
      try
      {
          main delete=new main();
  
          // int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells["id"].Value);
          // string ID = GridView1.Rows[e.RowIndex].ToString();
          sQLcONN.Open();
          string Query = "delete  * from shoppingcart where shoppingcart.with_puja = '"+Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString())+"' ";
          delete.deleteData(Query);
          Bindgrid();
          sQLcONN.Close();
      }
      catch (Exception ex)
      {
          Console.WriteLine("{0} Exception caught.", ex);
      }
  }
  </code></pre>