Skip to content

Instantly share code, notes, and snippets.

@RobbiNespu
Created June 1, 2015 07:30
Show Gist options
  • Save RobbiNespu/a19310898a5374cbf692 to your computer and use it in GitHub Desktop.
Save RobbiNespu/a19310898a5374cbf692 to your computer and use it in GitHub Desktop.
Select an item in asp.net dropdownlist by text
// 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