以编程方式将项添加到asp.net下拉列表 [英] Programmatically add items to asp.net dropdownlist
问题描述
我有一个下拉列表控件,我正在尝试在运行时从数据库中添加项目。但物品没有加载。这是我写的代码
私有 Sub Load_customer()
Dim objdatas 作为 DataSet
Dim retrieve As 新 GenBizData.Customer_Class
objdatas = retrievas.CUSTFILE_SHOWALL2
我 .cmd_Customer.DataSource = objdatas.Tables( CUSTFILE)
< span class =code-keyword> Me .cmd_Customer.DataTextField = CUST_NAME
我 .cmd_Customer.DataValueField = CUST_NUMBER
我 .cmd_Customer.Items.Add( CUST_NUMBER)
结束 Sub
检查一下: populatedropdown-vb [ ^ ]
< blockquote>试试这个
我 .cmd_Customer.DataValueField = CUST_NUMBER
我 .cmd_Customer.Databind()
我 .cmd_Customer.Items.Add( CUST_NUMBER)
Hi,
me.combobox.databind应该是最后一个声明并且有效
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
这篇关于以编程方式将项添加到asp.net下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!