c# - Index out of range exception while deleting row from GridView -
I'm having an error
"The index was out of range. Less than the size of the archive "
When attempting to delete the line of the gridview. My aspx.cs code is below:
Secure Zero GridView1_RowDeleting (Object Sender, GridViewDeleteEventArgs E) {try {main delete = new main ()} // Ind id = Convert. ToInt32 (GridView1. Rows [e.RowIndex] .sec ["id"]. Value); // string id = gridview 1. Ro [e. Rundex]. Ostring (); SQLcONN.Open (); String Query = "Remove from ShoppingCart * * * Where shoppingcart.v_puja = '" + convert. ToInt32 (GridView1.DataKeys [e.RowIndex] .Value.ToString ()) + "'"; Delete.deleteData (query); Bindgrid (); SQLcONN.Close (); } Hold (Exception preceded by {Console.WriteLine ("{0} was caught exception", prior); }}
Maybe DataKeys
It should be:
string query = "shopping record where shoppingcart.v_puja = '" + convert .toInt32 (e.Item.DataKeys ["nameOfKey"]. Value) tostring ( ) + "'";
or something like this:
Secure Zero GridView 1_Rove Delete (Object Sender, GridVidualEventEurges E) {try {main delete = new main ()} DataTable DT = Datasource as Gridview 1 datatable; SQLcONN.Open (); String query = "Remove shopping cart from shopping cart, where shoppingcart.v_poo = '" + convert "toint32 (dt.rows [e.rowindex] [" nameOfKey "]). ToString () + "'"; Delete.deleteData (query); Bindgrid (); SQLcONN.Close (); } Hold (Exception preceded by {Console.WriteLine ("{0} was caught exception", prior); }}
Where is the column name of the nameOfKey
table that is the with_puja
in your code and GridView1
< Code> E. Item should be if e
has a item
property
Comments
Post a Comment