Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

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

Hello,

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.
0
cesemj
Asked:
cesemj
  • 2
  • 2
1 Solution
 
digitalZoCommented:
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?
0
 
cesemjAuthor Commented:
Hello,

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,
0
 
digitalZoCommented:
Hello,

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)
        Else
            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?
0
 
cesemjAuthor Commented:
Thank you again, I am going to test it now and will let you know.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now