hi all,
When I delete a record from the gridview it gives me the following error:
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Line 116: int rowno= Convert.ToInt32(e.RowIndex);
Line 117: string delval = GridView1.Rows[rowno].Cells[1].Text;
Line 118: string strstate = "delete from tb_citystate_master where citystate_nm= '" + delval + "'";
But when I check with the database the record is deleted.
The flow of module is like this:
- When the form loads, the gridview is binded with the data from the database.
- The gridview has a button "Delete" for deleting a row.
- When the record is deleted the gridview is re-binded with the data from database(after deleting the current record).(I think the problem is somewhere here).
What should I do to slove this?
My databinding code is:
public void showstate()
{
string st = "Data Source=newgeneration;Initial Catalog=testcheema;Integrated Security=True";SqlConnection con = new SqlConnection(st);
con.Open();
string strstate = "select citystate_cd, citystate_nm from tb_citystate_master where statelink_cd=0";SqlDataAdapter adp = new SqlDataAdapter(strstate, con);DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
Regards,
Royal
Enter your message below
Sign in or Join us (it's free).