我试图在vb中设置下拉列表(UpdateDistributor)的默认值。
UpdateDistributor.DataValueField似乎不起作用。下拉列表保持空白
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Dim TitleSearch As String = "Select distrubtorcode from titles where isbn = 986765654"
Dim table As DataTable = Database.SelectRows(TitleSearch)
If table.Rows.Count > 0 Then
UpdateDistributor.DataValueField = table.rows(0)("distrubtorcode")
End if
End if
Dim SQLUpdateDistrubtor = "Select distinct distrubtorcode from titles "
MyData = Database.SelectRows(SQLUpdateDistrubtor)
For Each Row As DataRow In MyData.Rows
UpdateDistributor.Items.Add(New ListItem((Row)("companyname"), (Row)("companyname")))
Next
End Sub
答案 0 :(得分:0)
最后这就是我想出来的 - 我猜想之前也把信息放在了错误的位置! Combobox.Text =" yourText"工作了! - ty
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim TitleSearch As String = "Select distrubtorcode from titles where isbn = 986765654"
Dim table As DataTable = Database.SelectRows(TitleSearch)
Dim SQLUpdateDistrubtor = "Select distinct distrubtorcode from titles "
MyData = Database.SelectRows(SQLUpdateDistrubtor)
For Each Row As DataRow In MyData.Rows
UpdateDistributor.Items.Add(New ListItem((Row)("companyname"), (Row)("companyname")))
Next
If table.Rows.Count > 0 Then
UpdateDistributor.text = table.rows(0)("distrubtorcode")
End if
End Sub