To the source for System.Web.UI.WebControls.ListControlfrom which it is inferred DropdownList, it looks like the setting SelectedIndexactually calls ClearSelection(); and if not -1, it will go on to select the item.
public virtual void ClearSelection() {
for (int i=0; i < Items.Count; i++)
Items[i].Selected = false;
}
public virtual int SelectedIndex {
set {
...
if ((Items.Count != 0 && value < Items.Count) || value == -1) {
ClearSelection();
if (value >= 0) {
Items[value].Selected = true;
}
}
...
}
Edit: therefore, answering your question, the call ClearSelection()will directly save you from a few (non-essential) if statements.
source
share