VB.Net中的Combobox - 如何获得相应的id [英] Combobox in VB.Net - How to get corresponding id
问题描述
我有以下代码填充数据库中的下拉列表。这很好用。现在,当用户从列表中选择特定日期时,我想获得所选员工的天数ID。即我需要获得Dayid值。如果将Dayid加载到下拉列表中,我可以执行此操作,但在这种情况下,仅显示日期。请告诉我如何获取Dayid值,即使它未在下拉列表中加载。
这是我从数据库加载列表框的方式:
I have the following code which populates the dropdown lists from the database. This works fine. Now, when the user selects a particular days from the list, I want to get the Days Id of the selected employee. i.e. I need to get the Dayid value. I can do this if the Dayid is loaded in the dropdown list, but in this case only the days are displayed. Please let me know how I can get the Dayid value even though it is not loaded in the dropdown list.
This is how i load the listbox from the database:
For Each dr As DataRow In m_dtDelayedDeliveryDays.Rows
Me.cmbDelayedDeliveryDays.Items.Add(dr("DeliveryDelayDays"))
Next
m_dtDelayedDeliveryDays是我的数据表。
请帮助
m_dtDelayedDeliveryDays is my datatable.
Please help
推荐答案
您实际上需要单独添加ListItem,而不是在构造函数中。例如:
You actually need to add the ListItem separately, instead of in the constructor. For example:
For Each dr As DataRow In m_dtDelayedDeliveryDays.Rows
Dim tempList as New ListItem
tempList.Text = dr("DeliveryDelayDays")
tempList.Value = dr("DeliveryDelayDaysID")
Me.cmbDelayedDeliveryDays.Items.Add(tempList)
Next
这是来自记忆但这应该非常接近。你必须指定ID是什么。
This is from memory but that should be pretty close. You''ll have to specify what the ID is.
这篇关于VB.Net中的Combobox - 如何获得相应的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!