通过索引 ID 检索 DropDownList 的值
我试图通过指定其索引来检索下拉列表的值,但我似乎无法找到实现此目的的方法。我也不希望它成为选定的值,基本上我需要遍历列表,然后将其添加到数组中。我可以找到各种方法来根据值而不是索引 id 来获取它,有人知道如何做到这一点吗?我正在使用 c#。
I am trying to retrieve the value of a dropdown list by specifying its indexid but I cant seem to find a way to accomplish this. I dont want it to be the selected value either, basically I need to go through the list, and then add it to an array. I can find all kinds of ways to get it based on the value but not by the index id anyone know how to do this? Im using c#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
字符串 valueAtIndex = myComboBox.Items[SomeIndexValue].Value;
string valueAtIndex = myComboBox.Items[SomeIndexValue].Value;
您尝试过
lstWhatever.SelectedIndex
吗?由于该对象支持
IEnumerable
,因此您可以使用foreach
进行循环(如果您愿意的话)。Have you tried
lstWhatever.SelectedIndex
?Since the object supports
IEnumerable
, you can useforeach
to loop through, if that is your intention.这是您要找的吗?
其中,comboBox1 是您的下拉列表,我假设您正在谈论 Windows 窗体项目。
或者,如果您想使用索引 ID:
Is this what you are looking for?
Where comboBox1 is your dropdown list and i assumed you are talking about a windows forms project.
Or, if you want to us Index Id:
String valueAtIndex = myComboBox.Items[myComboBox.SelectedIndex].ToString();
String valueAtIndex = myComboBox.Items[myComboBox.SelectedIndex].ToString();