2011-02-16 87 views
0

我试图通过指定它的indexid检索下拉列表的值,但我似乎无法找到一种方法来实现此目的。我不希望它是选定的值,基本上我需要通过列表,然后将其添加到数组。我可以找到各种方式来获取它的价值,但不是由索引ID任何人都知道如何做到这一点?我使用C#。通过索引ID检索DropDownList的值

回答

5

string valueAtIndex = myComboBox.Items[SomeIndexValue].Value;

-2

String valueAtIndex = myComboBox.Items [myComboBox.SelectedIndex] .ToString();

+0

或者任何指标可以去括号内 – novacara 2011-02-16 21:06:21

0

你试过lstWhatever.SelectedIndex

由于对象支持IEnumerable,因此如果这是您的意图,则可以使用foreach进行循环。

0

这是你在找什么?

List<String> theList = new List<string>(); 
     foreach (var item in comboBox1.Items) 
     { 
      theList.Add(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()); 
      }