我有技術上的5列在GridView如何將我隱藏的主鍵值在GridView中傳遞給存儲過程?
- 修改和停用按鈕
- 名稱
- 電話
- 電子郵件
- [隱藏]用戶ID 「這是我對錶的主鍵」
我想將選定行的此userid值傳遞給我的更新存儲過程,該存儲過程將設置active = 0,其中us ERID = @用戶ID。
不知道是否有辦法傳遞選定的數據鍵或只傳遞選定的行隱藏列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();
}
}
見,如果它在['e.Values'](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewdeleteeventargs.values(V = VS。 110).aspx)或['e.Keys'](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewdeleteeventargs.keys(v = vs.110).aspx ) – stuartd