Add  a Dropdownlist to a page that update all related fields on a page

Posted on 2007-10-04
Last Modified: 2013-11-26

I would like to create a form that has a Dropdownlist on a page and when the partname is selected all related fields inthe Part table (PartNum, PartName, and PartVendor) associated with the partname selected will automatically be filled in on the form saving data entry time.  Thank you in advance.
Question by:cesemj
    LVL 10

    Expert Comment

    On Dropdown SelectedIndexChanged, type the code to generate the data from the database which you require and bind it to the form.

    Do you need an example?

    Author Comment


    Yes an example/tutorial.  I understand that I will have the dropdown box, ddbAuotName bound to a field in a table, tblAuotParts - AutoName.  I will have to Enable AutoPostBack the DropDownList box, but when I select the AutoPartName how do I provide an event handler for that to query the access database table, tblAutoParts, so that the fields AutoPartNumber and AutoModelType are automatically field in.

    Thank you,
    LVL 10

    Accepted Solution


    Sorry for the late response.

    Use the SelectedIndexChanged handler:

     Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
                Dim sQRY As String
    Dim dr as SqlDataReader
    Dim sqcom as SqlCommand
    Dim sqcon as SqlConnection

                sQRY = "[SELECT AutoPartNumber and AutoModelType FROM [tablename]] WHERE '" & DropDownList1.SelectedValue & "' "
                sqcom = New SqlCommand(sQRY, sqcon)

               dr = sqcom.ExecuteReader

               If dr.Read = True Then
                TextBox1.Text = dr.Item(0)
                TextBox2.Text = dr.Item(1)
                Label1.Visible = True
                Label1.Text = "No data"
            End If
     End Sub

    All the declarations should be before Page_Load. I've used it here in the Sub just for information.

    Does this help?

    Author Comment

    Thank you again, I am going to test it now and will let you know.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    vSphere client error 503 5 57
    vb linq Count Distinct? 1 30
    Javascript - getdate 5 36
    Unit testing, moq, best practices 7 20
    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…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now