0

我在 asp.net 中创建了一个数据网格,它加载了数据。我需要删除数据

OnItemCommand 事件。

所以有人知道这个,帮助我。

4

1 回答 1

0

你可以看到这个链接

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html

 protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     int userid =Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["UserId"].ToString());
     string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
     con.Open();
     SqlCommand cmd = new SqlCommand("delete from Employee_Details where UserId=" +userid, con);
     int result = cmd.ExecuteNonQuery();
     con.Close();
     if (result == 1)
     {
    BindEmployeeDetails();
    lblresult.ForeColor = Color.Red;
    lblresult.Text = username + " details deleted successfully";
     }
  }
于 2013-09-15T07:41:56.760 回答