以编程方式将项添加到asp.net下拉列表 [英] Programmatically add items to asp.net dropdownlist

查看:77
本文介绍了以编程方式将项添加到asp.net下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个下拉列表控件,我正在尝试在运行时从数据库中添加项目。但物品没有加载。这是我写的代码



 私有  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


谢谢,我找到了答案。



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


这篇关于以编程方式将项添加到asp.net下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆