DropDownList

J

Jim

Let's say we have a drop down list (lstStates) of the 50 states. Is there
another way to pre select a state, when the page loads, besides
lstStates.SelectedValue = "NY" for example?

The reason I'm asking is because when a value not in the 50 state master
list (for example, lstStates.SelectedValue = "TR"), the page erros out with a
"Specified argument was out of the range of valid values" error. I know the
correct answer is "well don't pass in TR" but that's another matter.

Is there another property of the DropDownList where if it's not in the
master list, it simply goes to the first item in the list? Or is there a
way/trick to handle this so the page doesn't error out.

Thanks in advance,
Jim
 
J

Jim

Nice..Thank you Phillip!

Phillip Williams said:
Dim li As ListItem
'This clears previous selections on the list
dropdownlist1.ClearSelection()
'returns a reference to the listitem with value TR
li = dropdownlist1.Items.FindByValue("TR")
'if no listitem has the value TR then we get nothing
If li Is Nothing Then
'set the first item as the selected item
dropdownlist1.SelectedIndex = 0
Else
li.Selected = True
End If
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top