我正在尝试在 VB.NET 中初始化一个下拉列表,但我的下拉列表没有填充任何值。我希望 DataTextField 与下拉列表中的 DataValues 不同。下拉列表应显示一系列字符串;DataValues 只能是数字。
我该如何实施?这是我现在的代码摘录:
Dim ProductList As New ArrayList()
Dim ProdCodeSearch As String
Dim InstrumentSearch As String
pcSQL = " select distinct instrument_name AS [instrument_name], product_code AS [product_code] from FRUD.tblXref order by instrument_name "
Dim DBConn As SqlConnection
DBConn = New SqlConnection(ConfigurationManager.AppSettings("AMDMetricsDevConnectionString"))
DBConn.Open()
Dim reader As SqlDataReader
Dim DBCommand As New SqlCommand(pcSQL, DBConn)
reader = DBCommand.ExecuteReader()
While reader.Read()
End While
dProdCodeSearch.Items.Add(reader(0))
dProdCodeSearch.DataTextField = "instrument_name"
dProdCodeSearch.DataValueField = "product_code"
dProdCodeSearch.DataBind()
reader.Close()