//int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
//if (con.State == ConnectionState.Closed)
//{
// con.Open();
//}
//SqlCommand cmd = new SqlCommand("Delete from gridview where id='" + id + "'", con);
//cmd.ExecuteNonQuery();
//con.Close();
//GridView1.DataBind();
//display();
how can i delete a row in using row deleting event . i was used this code but its not working in the table i use identity to generate id

Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Feb 26, 2014, 11:16 PM EST
KalaiRank #8,005 · 230 reputationPosted Feb 24, 2014, 3:08 AM EST
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("Delete from gridview where id='" + id + "'", con);
cmd.ExecuteNonQuery();
con.Close();
GridView1.DataBind();
display();
}
Nitin Sharma152 reputationPosted Feb 25, 2014, 10:37 PM EST
Index was out of range. Must be non-negative and less than the size of the collection.
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Feb 25, 2014, 10:56 PM EST
Nitin Sharma152 reputationPosted Feb 26, 2014, 10:59 PM EST
Nitin Sharma152 reputationPosted Feb 26, 2014, 11:05 PM EST
selva kumarRank #2,987 · 483 reputationPosted Feb 27, 2014, 12:26 AM EST
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
Label lblid = (Label)row.FindControl("lblid");
int T_ID = Convert.ToInt32(lblid.Text);
Con.Open();
Cmd = new SqlCommand("Delete From Tablename Where T_ID=" + T_ID + "", Con);
Cmd.ExecuteNonQuery();
Con.Close();
GridView1.EditIndex = -1;
gvbind();
}
Nitin Sharma152 reputationPosted Feb 27, 2014, 11:52 PM EST
thanku for ur support
Dear selva thanku for ur code but now my code is working using datakeynames field