Populating dropdown list from database (need help with sql - where to put it)
I have a dropdown list which is populated from the database. The second should then be populated with items from the database according to what was selected in the first. How do I say to only display the items if they have the category selected in the first box???
PS I am only using one table.
Thanks loads
Problem solved, I've noticed that loasds of people have the same problem so here is the code for the SelectedIndexChanged event:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim myconnection As SqlConnection
Dim mydata As SqlDataAdapter
Dim mydata7 As SqlDataAdapter
Dim ds7 As DataSet
myconnection = New SqlConnection("workstation id=****;packet size=4096;integrated security=SSPI;data source=""****\*" & _
"CGA"";persist security info=False;initial catalog=table")
mydata7 = New SqlDataAdapter("Select * from table ", myconnection)
ds7 = New DataSet
mydata7.Fill(ds7, "table")
Dim dav1 As New DataView(ds7.Tables("table"))
Dim strFilter As String
strFilter = "Category='" & DropDownList1.SelectedValue & "'".ToString
dav1.RowFilter = strFilter
DropDownList3.DataSource = dav1
DropDownList3.DataTextField = ds7.Tables(0).Columns("Question").ColumnName.ToString()
DropDownList3.DataValueField = ds7.Tables(0).Columns("Question").ColumnName.ToString()
DropDownList3.DataBind()
End Sub
Hope this helps anyone in the same situation!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks