且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式将项添加到asp.net下拉列表

更新时间:2023-11-30 15:34:58

检查一下: populatedropdown-vb [ ^ ]


试试这个



  .cmd_Customer.DataValueField =   CUST_NUMBER 
.cmd_Customer.Databind()
.cmd_Customer.Items.Add( CUST_NUMBER


谢谢,我找到了答案。



me.combobox.databind应该是最后一个声明并且有效


Hi,

I have a dropdownlist control and i am trying to add items from a database at runtime. but the items are not loading. this is the code I wrote

Private Sub Load_customer()


       Dim objdatas As DataSet

       Dim retrievas As New GenBizData.Customer_Class


       objdatas = retrievas.CUSTFILE_SHOWALL2

       Me.cmd_Customer.DataSource = objdatas.Tables("CUSTFILE")
       Me.cmd_Customer.DataTextField = "CUST_NAME"
       Me.cmd_Customer.DataValueField = "CUST_NUMBER"
       Me.cmd_Customer.Items.Add("CUST_NUMBER")

   End Sub

Check this out: populatedropdown-vb[^]


Try this

Me.cmd_Customer.DataValueField = "CUST_NUMBER"
      Me.cmd_Customer.Databind()
      Me.cmd_Customer.Items.Add("CUST_NUMBER")


Thanks I found the answer.

me.combobox.databind should be the last statement and it worked