Tuesday, November 10, 2009

Reset DropDownList to Default Value

Use following lines:

DropDownList1.SelectedIndex = 0;

or

DropDownList1.ClearSelection();
DropDownList1.Items.FindByText("--Select--").Selected = true;

or

DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue("--Select--").Selected = true;


Note:

We need to mention DropDownList1.ClearSelection(); before using DropDownList1.Items.FindByValue("--Select--").Selected = true
(or)DropDownList1.Items.FindByText("--Select--").Selected = true

Otherwise you will get an error 'Cannot have multiple items selected in a DropDownList'

No comments: