c# - dropdownlist doesn't lost his selected value but listbox does -
i have 2 user control 1 has dropdownlist other listbox, on main page there button when click button page goes postback , user controls session add controls on page. , can selected items drop down list list box cant sync viewstate guess.
what did try; binding session uc in page init, adding listbox datavalue , datatext, viewstate enable listbox(which default guess)
if think logic right must doing wrong in code let me know try paste here in simplified version.
here's code you're trying do, maybe you're not doing correct , can spot out.
protected void page_load(object sender, eventargs e) { var newlistbox = new listbox(); newlistbox.id = "anewid"; newlistbox.items.add("1"); newlistbox.items.add("2"); newlistbox.selectedindexchanged += lstboxchanged; panel1.controls.add(newlistbox); } private void lstboxchanged(object sender, eventargs e) { var newlistbox = sender listbox; if (newlistbox != null && newlistbox.selecteditem != null) { label1.text = newlistbox.selecteditem.text; } }
hope helps.
Comments
Post a Comment