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


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.
Who is Participating?

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?
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?
cesemjAuthor Commented:

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,
cesemjAuthor Commented:
Thank you again, I am going to test it now and will let you know.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.