Select dropdownlist item after button click

Asked
Viewd3214

0

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.)

3 ответов

1

DropDownList.SelectedIndex = -1

  • Doesn’t this assume that the top Item is the default one?

    Jack Marchetti16 октября 2009, 14:47
  • 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.

    PhilPursglove16 октября 2009, 14:54
0

Use

dropdownlist.ClearSelection()
0

In the click event can you do:

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

?