How to get DropDownList Value for a random Index?
Very important: I am NOT asking about开发者_如何学Go SELECTEDValue from a SelectedIndex.
How do I get the value of any index when it is not the selected index? For example, the selected index might be 5, but I want to get the value of item 9.
Thanks.
Try this:
string value = DropDownList1.Items[8].Value;
That will give the value at that index.
You need to check the Items
collection for the DropDownList which holds the ListItems
displayed in the dropdown.
you can access the same by using index as ddl.Items[index].Text
or ddl.Items[index].Value
and get the values, since it Zero based make sure you are passing in the right index else you may get Index out of bounds exception
So if you are looking for the 9th value seen in the dropdown it would be available at index 8 in the collection
精彩评论