Results 1 to 3 of 3

Thread: RESOLVED!! Adding Text and Value to DropDown

  1. #1

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381

    Question RESOLVED!! Adding Text and Value to DropDown

    How do you add text and Value to a dropdown programatically?

    Right now I use the binding method with no problems.

    VB Code:
    1. DropDownList1.DataTextField = "Name"
    2.             DropDownList1.DataValueField = "CustomerID"
    3.             DropDownList1.DataSource = SQLQuery()
    4.             DropDownList1.DataBind()

    However I have a need to do it manually on some of my dropdown web controls.

    I can add items into the collection but the TEXT and VALUE are both the same when it should have been (ex Finance, 001).

    VB Code:
    1. With DropDownList2
    2.                 .Items.Add("Finance")
    3.                 .Items.Add("Design")
    4.                 .Items.Add("Management")
    5.             End With


    **** DATA ****

    Dept Code
    ------- ------
    FINANCE 001
    DESIGN 002
    MANAGEMENT 003

    TIF
    Last edited by ARPRINCE; Apr 26th, 2004 at 08:46 AM.

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    The ListItemCollection.Add function is overloaded - you're currently using Combo.Items.Add(string). The second option is Combo.Items.Add(ListItem) - which would have the "ability" to do what you want:
    Code:
    With DropDownList2
        ' ListItem([Text], [Value]) constructor.
        .Items.Add(New ListItem("Finance", "001"))
    End With

  3. #3

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381

    Thumbs up

    This tip did the trick. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width