There is no "selected" property in a drop down list (I double checked to make sure). Are you refering to the "selected" property "SelectedItem" property?
When you select an item in a drop down list, it holds a reference to the selected item with the lowest index in the .SelectedItem property. If no items in the list are selected then the selectedItem property will be a null reference. You need to inspect the selecteditem reference before using it to ensure that it is acutally pointing to an item in the drop down list (in other words that you actually have an item in the drop down list selected). You do this as follows
If(Not ddlMyControl.SelectedItem Is Nothing)Then
'code here to work with the selected item...
End if
Keep in mind that if the selecteditem returns a listitem that logically that listitem's selected property will also return true.
If you are working with multiple selected items you need to get to them another way. Here is a snippet on how to do it.
Dim li as ListItem
For Each li in ddlMyList.Items
If(li.Selected)Then
'code here to work with the selected item...
End If
Next li
Thats roughly how I got it sorted.
My problem was that the search text has to be exactly like the text in the DDL.
So I used the following
Dim li as ListItem
li = DropDownList.Items.FindByText(strSearch)
if not IsNothing(li) then
DropDownList.Items.FindByText(strSearch).Selected = True
end if
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.