Created
June 1, 2015 07:30
-
-
Save RobbiNespu/a19310898a5374cbf692 to your computer and use it in GitHub Desktop.
Select an item in asp.net dropdownlist by text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Old technique | |
foreach (ListItem item in DropDownList1.Items) { | |
if (item.Text == defaultText) { | |
item.Selected = true; | |
break; | |
} | |
} | |
// 2nd technique | |
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf( DropDownList1.Items.FindByText( defaultText)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment