Can anyone tell me shortest way to add all items of dropdownlist in a List<string>
I want to populate a List<string>
with the values of a DropDownList
Can anyone tell me shortest way to add all items of dropdownlist in a List<string>
I want to populate a List<string>
with the values of a DropDownList
yep. Set the datasource to the List<string>
Assuming: ddl your dropdown list. ListOfStrings your list of strings.
This should work:
Your post was a little unclear are you adding items to the drop down list or to the list?
To add to the list: var list = new List(DropDownList.Items.Length);
To Add to the drop down list:
Depends if you want the ListItem Text and you are able to leverage 3.5