c# - How to pass my hidden primary key value in a gridview to a stored procedure? -
i have technically 5 columns in gridview
- edit , deactivate button
- name
- phone
- [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
Post a Comment