Hi , you can get the id of the record which the user clicked to delete by using the following (If u are binding the id to the first column, whether u make it visible or not)
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text); // use SQL Command or stored procedure or what ever way u follow to delte the record from the database.
Try this protected void Delete_Click (object sender, EventArgs e) {
GridViewRow r = grid1.SelectedRow; string id = r.Cells[0]; SqlConnection sql=new SqlConnection(.......); SqlCommand cmd=new SqlCommand("Delete from table where id="+id); }
3 comments:
protected void gvSample_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int i = e.RowIndex;
DataTable dt = (DataTable)Session["dt"];
dt.Rows[i].Delete();
dt.AcceptChanges();
gvSample.DataSource = dt.DefaultView;
gvSample.DataBind();
}
Hi ,
you can get the id of the record which the user clicked to delete by using the following (If u are binding the id to the first column, whether u make it visible or not)
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
// use SQL Command or stored procedure or what ever way u follow to delte the record from the database.
}
Hi,
Try this
protected void Delete_Click (object sender, EventArgs e)
{
GridViewRow r = grid1.SelectedRow;
string id = r.Cells[0];
SqlConnection sql=new SqlConnection(.......);
SqlCommand cmd=new SqlCommand("Delete from table where id="+id);
}
Post a Comment