Set Selected Value on Multiple Dropdowns - which depend on each other
Posted on 2006-07-18
I am pulling data out of a database into a form for en 'edit' administrative section.
I select my data etc..
I populate my textboxes just fine.
There is one textbox in particular 'zip_code' which is what another 'county' dropdown(sqldatasource) rely on for its values
Then there is a 'city' dropdown whos datasource depends on the value of 'county' for its values.
For the edit page workflow, id like the default values on page load (not postback) to populate with the values that have been written into the database.
so - i have tried looping throuh the controls and tetting the textbox.text values or dropdown.selectedvalue = datareader value
I get as far as county, but then city _will not_ auto select.
My best guess on this is that the sqldatasource webcontrols do thier stuff _after_ the Sub Page_Load? which is causing my problems?
Im probably wrong though..
Anyone have any idea how i can resolve this with out digging too deep into codebehinds?
Id rather not have to build dropdown lists by hand every time the page loads.
(example, user edits the zip_code and now a whole new set of issues arrises)
an ideal solution is one where the datasource webcontrols cause the dropdowns to 'just work' and enable viewstate keeps selected values across postbacks as long as the zip code doesnt change, in which case they select new values anyways (and it keeps them)