1

How to Select Value from Particular Index i.e. 0, 1st , 2nd ,3rd or 4th of DropDownList.

Using C#.

I have a DropDownList which have 6 items, now I like to Select 4th item form that DropDownList.

Note that the value of this item is unknown; as it may change time to time; but I know that it will be at 4th place in dropdown.

I this my try, which not working

string Item4;

item4 = DropDownList1.SelectedIndex = 3;

4

6 回答 6

1

字符串 item4 = DropDownList1.Items[3].Value;

于 2012-09-15T16:49:10.643 回答
1

要通过索引设置 Dropdown 的值,请使用以下命令:

DropDownList1.SelectedIndex = 3;

要从下拉列表中获取值,请使用:

String Value = DropDownList.SelectedItem.Value;

对于文本使用:

String Text = DropDownList.SelectedItem.Text;
于 2012-09-15T16:49:14.013 回答
1
 string item4 = DropDownList1.Items[3].Value;

 item4 = DropDownList1.SelectedIndex = 3; is not correct.
于 2012-09-15T16:52:13.797 回答
1
var listItem = dropDownList.Items[3];
var value = listItem.Value;
于 2012-09-15T16:52:53.400 回答
0
DropDownList1.SelectedIndex = 3;
string item = DropDownList.SelectedItem.Value;
于 2012-09-15T16:47:06.973 回答
0

这里有很多答案

ListItem item = DropDownList1.Items[3];
string value = item.Value;
string text = item.Text;
于 2012-09-15T16:53:26.950 回答