Select an item in a DropDownList in asp.net

Selecting an item in a DropDownList is in my opinion unnecessarily convoluted but that being said this is how you do it and it is kind of logical. Assuming we have a list called myList and we want to select the item with the text "fred".

myList.SelectedIndex = 
    myList.Items.IndexOf(myList.Items.FindByText("Fred"));
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s