Finding DropDownList Index Based on the Item Value

When you need to set initial DropDownList on Page_Load method to the value from database, you can use

// If you want to find text by value field.
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue("x")); 
// If you want to find text by TextField.
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText("x"));

No comments:

Post a Comment