我在asp.net中创建了一个datagrid,它加载了数据。我需要删除数据
OnItemCommand事件。
所以任何人都知道这一点,帮助我。
答案 0 :(得分: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";
}
}