Drop down list need help

Posted on 2005-05-11
Last Modified: 2010-04-07
I have an <ASP:dropdownlist> with 10 values (not from the DB), but in my DB I have a value that relate to the dropdownlist. How can I get the dropdownlist match the values from my db?

Question by:Ennio
    LVL 24

    Expert Comment

    by:Jeff Certain
    How are the DB and DDL values related?
    LVL 6

    Expert Comment

    Not sure what you want. Why don't you populate the dropdown from the db, so that it will match the values in db?
    LVL 9

    Accepted Solution

    How about something like this...

    Sub Page_Load(Src As Object, E As EventArgs)

        'Connect to the database...
        Dim myDataset as Dataset
            'Create the dataset...
        Dim myValue = myDataset.Tables(0).Rows(0).Item("myItemValue")
            ' Here's where we set the Selected Item to the DB value
            ddl_MyDropDownList.SelectedIndex = ddl_MyDropDownList.Items.IndexOf(ddl_MyDropDownList..Items.FindByValue(myValue))

    End Sub
    LVL 1

    Author Comment

    I added to the DB and I can display fine.... thnks

    Now, can I populate more then 1 dropdown at the same time with the same dataset? or I need to have one fore each one?
    LVL 24

    Assisted Solution

    by:Jeff Certain
    Same dataset or datatable? You can populate with either. When you use a dataset, the DDL assumes table(0).

    You can do this to populate multiple DDL form teh same dataset, same table:

    Same DS, different tables (you can reference them by index or name):

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now