In code-behind I can do this to select something:
// Select item in first DropDownList myCascadingDropDown_1.SelectedValue = itemValue_1+":::"+itemText_1; // Select item in second DropDownList myCascadingDropDown_2.SelectedValue = itemValue_2+":::"+itemText_2;
(I'm aware, that I could search the list and set the selectedIndex property for each dropdown, but I have many items and i'm very lazy.)
npups answer works: I can select my desired item in the first dropdownlist. The problem is however, that new values based on that selected item (it is a CascadingDropDown, remember?) don't show in the second dropdown so I can't select anything there. I would need to somehow invoke the update method of the second dropdown manually: any suggestions?
Check this out:
Setting the value of the select element fixes that.
Firefox gets it right even if you just use the tags' content as values (instead of specifying a value in the option's value attribute). Not sure about other browsers.
EDIT, more stuff:
So there is some other select (or equivalent) that is updated by some harmonizing function when the first select changes?
Here, i have it in the first select's
onchange. When the selected element is set with this "value-setting" technique, the
onchange isn't triggered. Though, one can call the harmonizing function manually when you change the first select. I show two different ways (both in comments) below.
I didn't bother to hide global variables etc. here, but of course that is a good idea.
I was able to solve this:
1) With npups suggestion I was able to set "myCascadingDropDown_1" to my desired value.
2) Using the
method I was able to force the second dropdown to repopulate based on the new selected value of "myCascadingDropDown_1".
3) I wrote a timer to check periodically if the second dropdown has finished repopulation and set the desired value if it has (again using npups answer)..
you can also use myCascadingDropDown_2.set_SelectedValue(resultval, resultVal) instead of timer (item3)
©2020 All rights reserved.