c# - Public variable loses value on button click event asp.net -
i have checkboxes in asp.net gridview , have method select multiple checkboxes , works great. after when user inputs value in textbox updated rows selected values set null again? have included method of checking multiple items , update button. why values not being retained , how can fix it?
public variables
public string values = ""; public string salesordernumber;
multiple checkboxes
protected void selectcheckbox_oncheckedchanged(object sender, eventargs e) { checkbox chk = sender checkbox; var rows = dropdeadgridview.rows; int count = dropdeadgridview.rows.count; (int = 0; < count; i++) { bool ischecked = ((checkbox)rows[i].findcontrol("selectcheckbox")).checked; if (ischecked) { values += rows[i].cells[1].text + ","; rows[i].bordercolor = system.drawing.color.red; rows[i].forecolor = system.drawing.color.red; rows[i].borderstyle = borderstyle.inset; } } }
update button
protected void updatebutton_click(object sender, eventargs e) { app_code.griddata griddata = new app_code.griddata(); if (loadnumtextbox.text == "" && raddatetimepicker1.selecteddate != null) { sqlconnection dbconn = app_code.dbhelper.getconnection(); try { using (dbconn) { sqlcommand addjob = new sqlcommand(@"update order_detail set dropdeadtime = @dropdeadtime sales_order_number = @salesordernumber", dbconn); //addjob.parameters.addwithvalue("@salesordernumber", convert.toint32(idtextbox.text)); addjob.parameters.addwithvalue("@salesordernumber", values); addjob.parameters.addwithvalue("@dropdeadtime", raddatetimepicker1.selecteddate); dbconn.open(); addjob.executenonquery(); } notificationlabel.text = "updated!"; notificationlabel.visible = true; } catch (exception ex) { throw ex; } bindlist(); } if (loadnumtextbox.text != "" && raddatetimepicker1.selecteddate == null) { sqlconnection dbconn = app_code.dbhelper.getconnection(); try { using (dbconn) { sqlcommand addjob = new sqlcommand(@"update order_detail set load_number = @load_number sales_order_number = @salesordernumber", dbconn); addjob.parameters.addwithvalue("@salesordernumber", salesordernumber); addjob.parameters.addwithvalue("@load_number", loadnumtextbox.text); dbconn.open(); addjob.executenonquery(); } notificationlabel.text = "updated!"; notificationlabel.visible = true; } catch (exception ex) { throw ex; } bindlist(); }
if want live between requests you'll have use session-state, view-state, cookie, or html form / request value.
asp.net stateless meaning not keep state post postback.
you need static 1 if want achieve goal.
Comments
Post a Comment