It absolutely floors me that they didn't include a Boolean argument for 'Selected!'
Is there a wayâin codeâto set one of the options in a select element to be the selected item?
Of course setting an item as selected can be done in the web page, but I don't see a way to do this in code:
Code:
<asp:DropDownList id="D1" runat="server">
<asp:ListItem [u]Selected=True</u> Value="Val 1"></asp:ListItem>
<asp:ListItem Value="Val 2"></asp:ListItem>
</asp:DropDownList[blue]>
I tried using an HtmlSelect control, and putting a literal between the <select> and </select>, but that generates an error, because an HtmlSelect item cannot have an asp:literal child.
But if I create the whole <select> list within a literal, I suspect I will not be able to use the _ServerChange() event to test whether the user has made a selection on that element.
Sheesh! What I want to do is so cotton-pickinâ easy, but every board I come up with to span this chasm is just too short to do the job...
I need to fill one list (Nouns) from the database.
When a noun is selected, I need to modify a second list of Noun-Name Modifiers, and repaint the page in a fashion that keeps the selection made on the Nouns DDL.
So if they pick a noun like "A/C Plant," the modifier list gets 2 options: Nothing or "363 TON, R-114."
If they pick "Air Conditioner," the modifier list gets 2 options: Nothing or "SELF-CONTAINED."
If they pick "Alarm," the modifier list gets 3 options: Nothing, "BELL" or "WATER SWITCH."
The modifier list has to change to reflect the currently-selected noun.
I have a function, Nouns() which returns all the nouns, just as a string of options, their values, and their text, in straight HTML. I can easily adapt this to accept a value, and set the option that matches that argument to selected. But how to then get the noun selection list to have that set of options for its inner html (while still retaining the ability to use the ServerChange() event?
Ideas?
Comments?
Alternate approaches?
(I have this working perfectly in VB6/IIS. Seems upgrading ought not to remove functionality...)