Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DropDownList

Reply
Thread Tools

DropDownList

 
 
Jim
Guest
Posts: n/a
 
      11-10-2005
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
 
Reply With Quote
 
 
 
 
Jim
Guest
Posts: n/a
 
      11-10-2005
Nice..Thank you Phillip!

"Phillip Williams" wrote:

> 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
>
>
> "Jim" wrote:
>
> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList inside GridView: How to set SelectedIndex for the DropDownList? keithb ASP .Net 1 11-01-2006 05:24 AM
GridView: Filter DropDownList for another DropDownList =?Utf-8?B?SnVhbmpv?= ASP .Net 0 12-29-2005 07:44 AM
GridView: Filtr DropDownList from another DropDownList =?Utf-8?B?SnVhbmpv?= ASP .Net 0 12-23-2005 01:31 PM
databinding a Dropdownlist to another dropdownlist tshad ASP .Net 8 10-19-2005 10:00 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM



Advertisments