今天遇到个问题:
我需要查询SQL中的数据实现多个ComboBox级联, cboNozStyle.ValueMember = mItem("MinorCd").ToString() 也获取到了值,但是第二级我使用
cboNozStyle.SelectedValue.ToString取出来的确是空值!有人知道如何解决吗!
'第一级
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
cboNozStyle.Items.Clear()
Dim dal As SqlHelper1 = New SqlHelper1()
Dim Sqltext As String = "select * from NozStyle Where StatusYn Like 'Y'"
Dim dtUser = dal.QueryNo(Sqltext, CommandType.Text)
If dtUser.Rows.Count > 0 Then
For Each mItem As DataRow In dtUser.Rows
cboNozStyle.Items.Add(mItem("MinorTransNm").ToString()) '下拉菜单中显示类型
cboNozStyle.ValueMember = mItem("MinorCd").ToString() '将类型ID保存到ComboBox的隐藏值中
Next
End If
End Sub
'第二级
Private Sub cboNozStyle_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboNozStyle.SelectedIndexChanged
cboNozSize.Items.Clear()
Dim dal As SqlHelper1 = New SqlHelper1()
Dim Sqltext As String = "select t1.MinorTransNm,t1.MinorCd from NozSize as t1 where t1.RelCd1='" + cboNozStyle.SelectedValue.ToString + "'"
Dim dtUser = dal.QueryNo(Sqltext, CommandType.Text)
If dtUser.Rows.Count > 0 Then
For Each mItem As DataRow In dtUser.Rows
cboNozSize.Items.Add(mItem("MinorTransNm").ToString())
cboNozSize.ValueMember = mItem("MinorCd").ToString()
Next
End If
End Sub