C# 按索引ID检索DropDownList的值
我试图通过指定下拉列表的indexid来检索下拉列表的值,但我似乎找不到实现这一点的方法。我也不希望它是选中的值,基本上我需要遍历列表,然后将其添加到数组中。我可以找到各种各样的方法来获得它的基础上的值,但不是由索引id有人知道如何做到这一点?我正在使用c#.字符串值index=myComboBox.Items[myComboBox.SelectedIndex].ToString() String valueAtIndex=myComboBox.Items[myComboBox.SelectedIndex].ToString() 您是否尝试过C# 按索引ID检索DropDownList的值,c#,drop-down-menu,C#,Drop Down Menu,我试图通过指定下拉列表的indexid来检索下拉列表的值,但我似乎找不到实现这一点的方法。我也不希望它是选中的值,基本上我需要遍历列表,然后将其添加到数组中。我可以找到各种各样的方法来获得它的基础上的值,但不是由索引id有人知道如何做到这一点?我正在使用c#.字符串值index=myComboBox.Items[myComboBox.SelectedIndex].ToString() String valueAtIndex=myComboBox.Items[myComboBox.Selected
lstnother.SelectedIndex
由于该对象支持
IEnumerable
,因此如果您想循环,可以使用foreach
进行循环。您是否尝试过lstnother.SelectedIndex
由于该对象支持
IEnumerable
,因此如果您愿意,可以使用foreach
进行循环代码>字符串值index=myComboBox.Items[SomeIndexValue].Value代码>这就是你要找的吗
List<String> theList = new List<string>();
foreach (var item in comboBox1.Items)
{
theList.Add(item.ToString());
}
List theList=新列表();
foreach(comboBox1.Items中的变量项)
{
添加(item.ToString());
}
其中comboBox1是您的下拉列表,我假设您谈论的是一个windows窗体项目
或者,如果您想使用索引Id:
List<string> theList = new List<string>();
for (int i = 0; i < comboBox1.Items.Count; i++)
{
theList.Add(comboBox1.Items[i].ToString());
}
List theList=新列表();
对于(int i=0;i
这就是你要找的吗
List<String> theList = new List<string>();
foreach (var item in comboBox1.Items)
{
theList.Add(item.ToString());
}
List theList=新列表();
foreach(comboBox1.Items中的变量项)
{
添加(item.ToString());
}
其中comboBox1是您的下拉列表,我假设您谈论的是一个windows窗体项目
或者,如果您想使用索引Id:
List<string> theList = new List<string>();
for (int i = 0; i < comboBox1.Items.Count; i++)
{
theList.Add(comboBox1.Items[i].ToString());
}
List theList=新列表();
对于(int i=0;i
或任何索引都可以放在括号内,括号应为myComboBox.Items[myComboBox.SelectedIndex].Value.ToString()代码>或任何索引都可以放在括号内,括号应为myComboBox.Items[myComboBox.SelectedIndex].Value.ToString()代码>