【发布时间】:2024-05-23 17:40:02
【问题描述】:
从技术上讲,我在 gridview 中有 5 列
- 编辑和停用按钮
- 姓名
- 电话
- 电子邮件
- [隐藏] 用户 ID“这是我在桌子上的主键”
我想将此选定行的用户 ID 值传递给我的更新存储过程,该过程将设置 active=0,其中 userid=@userid。
不确定是否有办法传递选定的数据键或仅传递选定的行隐藏列 4,这将是索引中的 5,或者您是否有任何其他更好的方法。
protected void gvRowDeleting2(object sender, GridViewDeleteEventArgs e)
{
String strConnString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_update_user_active";
cmd.Parameters.Add("@userid", SqlDbType.VarChar).Value = userID; ******NEED HELP HERE****
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
buildcontractoradmingv();
}
catch (Exception ex)
{
throw ex;
}
finally
{
/*Display message saying company is deactivated*/
string message = "User has been removed";
string script = "window.onload = function(){ alert('";
script += message;
script += "')};";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
con.Close();
con.Dispose();
}
}
【问题讨论】: