DropDownList

Discussion in 'ASP .Net Web Controls' started by Jim, Nov 10, 2005.

  1. Jim

    Jim Guest

    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
    Jim, Nov 10, 2005
    #1
    1. Advertising

  2. Jim

    Jim Guest

    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
    Jim, Nov 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,587
    mr2_93
    Oct 2, 2005
  2. tshad
    Replies:
    8
    Views:
    2,210
    tshad
    Oct 19, 2005
  3. =?Utf-8?B?SnVhbmpv?=

    GridView: Filtr DropDownList from another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,851
    =?Utf-8?B?SnVhbmpv?=
    Dec 23, 2005
  4. =?Utf-8?B?SnVhbmpv?=

    GridView: Filter DropDownList for another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,286
    =?Utf-8?B?SnVhbmpv?=
    Dec 29, 2005
  5. keithb
    Replies:
    1
    Views:
    11,920
    shauns1
    Nov 1, 2006
Loading...

Share This Page