c# - dropdown value selecting only first value -
in below c# code though choosing own year still value passed 1920 only. can see values being displayed in dropdown box when choose value , submit 1920 being passed database.
protected void page_load(object sender, eventargs e) { dropdownlist3.items.clear(); (int = 1920; <= 2000; i++) { dropdownlist3.items.add(i.tostring()); } } protected void button1_click(object sender, eventargs e) { sbtc.dex(dropdownlist3.selecteditem); }
can tell me did mistake?
because when click on button again executing code in page_load
event. solution set dropdown values once. can use page.ispostback
property check whether initial load or postback.
protected void page_load(object sender, eventargs e) { if(!ispostback) { dropdownlist3.items.clear(); (int = 1920; <= 2000; i++) { dropdownlist3.items.add(i.tostring()); } } }
Comments
Post a Comment