Featured post
asp.net - Proper way to populate dropdownlist based off another value? -
i'm running minor issue asp.net code i'm working on. simplicity sake lets have 2 dropdownlists, 1 full of various items , full of other items, based off selected item of first dropdownlist. set variables hidden inputs check see if item in first dropdownlist has changed , if has change second dropdownlist, i'm having check make sure if else causes postback not repopulate second dropdownlist not lose selected user. check allows me make sure when navigate away page, correct values selected , not replaced postback repopulation.
i'm new asp.net/html/css/javascript , like. know while have works, isn't close being correct way things. please me correct ways , figure out best way solve current problem. asp.net tutorial websites nice need keep improving skills it.
try autopostback true selected index changed event:
<asp:dropdownlist id="dropdownlist1" autopostback="true" onselectedindexchanged="dropdownlist1_selectedindexchanged" runat="server" /> <asp:dropdownlist id="dropdownlist2" runat="server" />
and have event populate second dropdown:
protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) { }
edit if need populate first page load following, or better still make method called both page load , selected index changed populate dropdown.
if (!page.ispostback) { dropdownlist1_selectedindexchanged(dropdownlist1, eventargs.empty); }
- Get link
- X
- Other Apps
Comments
Post a Comment