I am dragging in dropdownlist controls to my aspx page. When I write any query in the asppx.vb page and try to bind it to my ddl the ddl remains unbound. I have tried several different ways of doing it and none are working. Even if I just create a blank page with a ddl and the most simple query it still won't bind. I have tried clicking on the ddl and binding to a linq datasource that way and they will bind but I can't use that method as it is unsuitable. I need to populate a ddl from a table called Buildings
and then, based on the selection from that ddl, populate another one from a table called Rooms
.
Protected Sub ddlBuilding_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBuilding.SelectedIndexChanged
Dim db As New OrionDataClassesDataContext
ddlBuilding.DataSource = (From build In db.Buildings
Select {build.Building_code, build.Building_name}).ToList()
ddlBuilding.DataTextField = "Building_name"
ddlBuilding.DataValueField = "Building_code"
ddlBuilding.DataBind()
End Sub
This is one method I have tried. Another method I tried is:
Protected Sub ddlBuilding_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBuilding.SelectedIndexChanged
Dim db As New OrionDataClassesDataContext
Dim building = (From build In db.Buildings
Select {build.Building_code, build.Building_name}).ToList()
ddlBuilding.DataSource = building
ddlBuilding.DataTextField = "Building_name"
ddlBuilding.DataValueField = "Building_code"
ddlBuilding.DataBind()
End Sub
At this stage I don't think the query is the problem. There is something that is stopping the .databind
and .datasource
functions from having any effect. I have tried this with several ddls. If anyone has any ideas please let me know. Desperate.
I have fixed the problem. I managed to just add LinqDataSources to the tables and select a Where clause to relate the two tables. I didn't think that would be possible for this issue but I was wrong