//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 SankaranarayanPosted Feb 27, 2014, 4:16 AM
Nitin SharmaPosted Feb 28, 2014, 4:52 AM
thanku for ur support
Dear selva thanku for ur code but now my code is working using datakeynames field
selva kumarPosted Feb 27, 2014, 5:26 AM
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 SharmaPosted Feb 27, 2014, 4:05 AM
Nitin SharmaPosted Feb 27, 2014, 3:59 AM
Lakshmanan Sethu SankaranarayanPosted Feb 26, 2014, 3:56 AM
Nitin SharmaPosted Feb 26, 2014, 3:37 AM
Index was out of range. Must be non-negative and less than the size of the collection.
KalaiPosted Feb 24, 2014, 8:08 AM
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();
}