c# - How to pass my hidden primary key value in a gridview to a stored procedure? -


i have technically 5 columns in gridview

  1. edit , deactivate button
  2. name
  3. phone
  4. email
  5. [hidden] userid "which primary key on table"

i want pass userid value of selected row update stored procedure set active=0 userid=@userid.

not sure if there way pass selecteddatakey or pass selected row hidden column 4 5 in index or if have other better ways.

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 here****      cmd.connection = con;      try     {         con.open();         cmd.executenonquery();         buildcontractoradmingv();     }     catch (exception ex)     {         throw ex;     }         {         /*display message saying company 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();     } } 

can try this:

string userid = yourgrid.rows[e.rowindex].cells[indexofhiddencol].text; 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -