asp.net - Values are not updating -
protected void gvexample_rowupdating(object sender, gridviewupdateeventargs e) { string s = gvexample.datakeys[e.rowindex].value.tostring(); textbox firstname = gvexample.rows[e.rowindex].findcontrol("txtfirstname") textbox; textbox lastname = gvexample.rows[e.rowindex].findcontrol("txtlastname") textbox; textbox title = gvexample.rows[e.rowindex].findcontrol("txttitle") textbox; textbox country = gvexample.rows[e.rowindex].findcontrol("txtcountry") textbox; string query ="update user_details set last_name='" + lastname.text + "',first_name='" + firstname.text + "',title='" + title.text + "',country='" + country.text + "'"; sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["sqlconnection"].connectionstring); sqlcommand cmd = new sqlcommand(query, con); con.open(); cmd.executenonquery(); con.close(); gvdatabind(); } the values not updating. updating lastname.text firstname.text. please me.
it sounds variables firstname etc not being cast textbox properly... if try following cast
gridviewrow row = gvexample.rows[e.rowindex]; var id = ((textbox)(row.cells[0].controls[0])).text; var firstname = ((textbox)(row.cells[1].controls[0])).text; var lastname = ((textbox)(row.cells[2].controls[0])).text; string query ="update user_details set last_name='" + lastname + "',first_name='" + firstname "'"; // , other values... obviously including clause , int.parse id value , making example code you've shown more production ready.
Comments
Post a Comment