Selecting an item in a drop down list

Discussion in 'ASP .Net' started by KatMagic, Apr 10, 2006.

  1. KatMagic

    KatMagic Guest

    How do you force a drop down list to default to a particular item based on
    its value?

    I have a drop down list with options Yes, No, Maybe, All, and I would like
    it to default to "All"

    This is my code, what am I doing wrong?
    ddlBilling.SelectedIndex =
    ddlBilling.Items.IndexOf(ddlBilling.Items.FindByValue("All"))
     
    KatMagic, Apr 10, 2006
    #1
    1. Advertising

  2. KatMagic

    Brock Allen Guest

    ddl.ClearSelection() // in case something else is selected
    ddl.Items.FindByValue("All").Selected = true

    -Brock
    http://staff.develop.com/ballen


    > How do you force a drop down list to default to a particular item
    > based on its value?
    >
    > I have a drop down list with options Yes, No, Maybe, All, and I would
    > like it to default to "All"
    >
    > This is my code, what am I doing wrong?
    > ddlBilling.SelectedIndex =
    > ddlBilling.Items.IndexOf(ddlBilling.Items.FindByValue("All"))
     
    Brock Allen, Apr 10, 2006
    #2
    1. Advertising

  3. That looks fine...is that the value of the dropdown or the text?

    if it's the text, you need to use FindByText

    Otherwise, where is this code?are you binding before?

    Karl

    --
    http://www.openmymind.net/



    "KatMagic" <> wrote in message
    news:...
    > How do you force a drop down list to default to a particular item based on
    > its value?
    >
    > I have a drop down list with options Yes, No, Maybe, All, and I would like
    > it to default to "All"
    >
    > This is my code, what am I doing wrong?
    > ddlBilling.SelectedIndex =
    > ddlBilling.Items.IndexOf(ddlBilling.Items.FindByValue("All"))
    >
    >
     
    Karl Seguin [MVP], Apr 10, 2006
    #3
  4. KatMagic

    KatMagic Guest

    Thanks everyone you were very helpful. As you suggested, I was incorrectly
    attempting to select by value, when "All" was a text value. Clearing the
    selection and selecting by the actual value (0), worked! Thanks.

    "KatMagic" <> wrote in message
    news:...
    > How do you force a drop down list to default to a particular item based on
    > its value?
    >
    > I have a drop down list with options Yes, No, Maybe, All, and I would like
    > it to default to "All"
    >
    > This is my code, what am I doing wrong?
    > ddlBilling.SelectedIndex =
    > ddlBilling.Items.IndexOf(ddlBilling.Items.FindByValue("All"))
    >
    >
     
    KatMagic, Apr 11, 2006
    #4
    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. Bogdan Zamfir

    Selecting an item in a drop down list

    Bogdan Zamfir, Aug 17, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    437
    Bogdan Zamfir
    Aug 17, 2003
  2. Natty Gur
    Replies:
    1
    Views:
    326
    Bogdan Zamfir
    Aug 18, 2003
  3. Andrew
    Replies:
    2
    Views:
    520
    Jukka K. Korpela
    Apr 15, 2005
  4. weiwei
    Replies:
    0
    Views:
    1,050
    weiwei
    Jan 5, 2007
  5. Replies:
    5
    Views:
    303
Loading...

Share This Page