为什么这个下拉列表没有填充?

时间:2017-04-12 20:59:36

标签: vb.net html-select

我有三个下拉菜单;第二个(成员)根据第一个(单位)中的内容填充,第三个(客户)应根据第二个中的内容填充;但事实并非如此。

这是在LINQPad中有效的查询(返回公司名称列表):

select distinct companyname from customers C left join members M on M.MemberNo = C.MemberNo where M.MemberNo = '052' order by companyname

...但在以下代码中不起作用:

'Populate the Members dropdown
Dim selectedUnit As String = DropDownListUnits.Text
Dim membersDT As DataTable
sql = "select distinct shortname, M.memberno from members M left join memberunitproducts mup on M.MemberNo = mup.MemberNo where unit = '" + selectedUnit  + "' order by shortname"
retDS = sqlDAL.runSQLDataSet(sql)
membersDT = retDS.Tables(0)
DropDownListMembers.DataSource = membersDT
DropDownListMembers.DataTextField = "shortname"
DropDownListMembers.DataValueField = "memberno"
DropDownListMembers.DataBind()

'Populate the Customers dropdown
Dim selectedMember As String = DropDownListMembers.DataValueField
Dim customersDT As DataTable
sql = "select distinct companyname from customers C left join members M on M.MemberNo = C.MemberNo where M.MemberNo = '" + selectedMember  + "' order by companyname"
retDS = sqlDAL.runSQLDataSet(sql)
customersDT = retDS.Tables(0)
DropDownListCustomers.DataSource = customersDT
DropDownListCustomers.DataTextField = "companyname"
DropDownListCustomers.DataValueField = "companyname"
DropDownListCustomers.DataBind()

第三个(客户)下拉列表在运行时仍未填充 - 为什么?

可能不需要,但这是第一个(“单位”)下拉列表的代码:

'Populate the Units dropdown
Dim unitsDT As DataTable
sql = "Select distinct unit from masterunits where abs(active) = 1"
retDS = sqlDAL.runSQLDataSet(sql)
unitsDT = retDS.Tables(0)
DropDownListUnits.DataSource = unitsDT
DropDownListUnits.DataTextField = "unit"
DropDownListUnits.DataValueField = "unit"
DropDownListUnits.DataBind()

我错过了什么或做错了什么?

1 个答案:

答案 0 :(得分:1)

我不得不改变这个:

Dim selectedMember As String = DropDownListMembers.DataValueField

......对此:

Dim selectedMember As String = DropDownListMembers.SelectedItem.Value