I've worked out how to create a DropDownList using the following code:
<select id="salesPersonDropList" runat="server"></select>
In my .aspx page, then my code behind loops through database output running:
Dim newListItem As ListItem
newListItem = New ListItem("Title", "Value")
salesPersonDropList.Items.Add(newListItem )
What I can't figure out is how to programatically set which of the List Items created is the one to be pre-selected in the rendered DropDownList, ie, how to create what I'd write in HTML as:
<select>
<option value="1">1</option>
<option selected value="2">2</option>
</select>
Based on database output. As the code behind loops through the database output it should compare the output to a session variable and if they values match, the ListItem should be the item selected in the rendered DropDown.
Set your Selected
property of the ListItem
to true:
Dim newListItem As ListItem
newListItem = New ListItem("Title", "Value")
newListItem.Selected = True
salesPersonDropList.Items.Add(newListItem )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With