我将下拉列表控件拖到我的 aspx 页面。当我在 asppx.vb 页面中编写任何查询并尝试将其绑定到我的 ddl 时,ddl 仍然未绑定。我尝试了几种不同的方法,但都没有奏效。即使我只是用 ddl 和最简单的查询创建一个空白页面,它仍然不会绑定。我曾尝试单击 ddl 并以这种方式绑定到 linq 数据源,它们会绑定,但我不能使用该方法,因为它不合适。我需要从名为的表中填充一个 ddl Buildings
,然后根据从该 ddl 中的选择,从名为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
这是我尝试过的一种方法。我尝试的另一种方法是:
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
在这个阶段,我认为查询不是问题。有一些东西会阻止.databind
and.datasource
函数产生任何影响。我已经用几个 ddls 试过了。如果有人有任何想法,请告诉我。绝望的。