views:

292

answers:

2

I have an asp drowndownlist and I'd like to change its selection after a button click. I can't seem to find a way to do this, is there a way? (Its a reset button of sorts, and I would like the dropdownlist to return to the "default" value.)

A: 

In the click event can you do:

DropDownList.SelectedItem = "whatever";
DropDownList.DataBind()

?

Jack Marchetti
SelectedItem is readonly?
Shawn
+1  A: 

DropDownList.SelectedIndex = -1

PhilPursglove
Doesn't this assume that the top Item is the default one?
Jack Marchetti
No. Because the index is zero-based, the item at index 0 could be a valid selection. Setting SelectedIndex to -1 means nothing is selected. Or that's my understanding anyways.
PhilPursglove