c# - I am having an issue in accessing dropdown list value -
the problem getting name dropdown list , getting pupil id of name table.
protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) { dropdownlist ddl = sender dropdownlist; stud_name1 = ddl.selectedvalue;// sends value // label1.text = ddl.selectedvalue; string getquery = "select studnt_id pupil name='"+stud_name1+"'"; getidcon.open(); sqlcommand getid = new sqlcommand(getquery, getidcon); stdid1 = ((int)getid.executescalar());// gives id in homecoming selection // session [stdid1] // label1.text = stdid1.tostring();// testing value // roll number }
after getting id store in stdid1 global variable, not getting value stored in stdid1 variable in button code.
protected void button1_click(object sender, eventargs e) { label1.text = stdid1.tostring(); }
so stdid1
field in class. variables not persisted across postbacks in asp.net, disposed page rendered client.
so utilize viewstate
or session
store it. don't know why need variable @ when have dropdownlist
stores selectedvalue
in viewstate
anyway.
protected void button1_click(object sender, eventargs e) { label1.text = dropdownlist1.selectedvalue; }
nine options managing persistent user state in asp.net application
update
after reading question again, i've seen want store id in variable dropdownlist
has name. assume you've used name both datatextfield
and datavaluefield
. utilize name text , id value.
dropdownlist1.datatextfield = "studnt_id"; dropdownlist1.datavaluefield = "name"; dropdownlist1.datasource = getstudents(); dropdownlist1.databind();
c# asp.net sql-server
No comments:
Post a Comment