Clearing and setting selected value of asp:dropdownlist

December 13, 2011 Chuck .NetProgrammingVB.NetVisual Basic

On page postback when a “clear selection” button was pressed, I wanted to set the value of a drop down list back to the default state.


'ddldays is the ID of the asp:dropdownlist in my application.
'first we clear the current selection, this prevents an error where the application thinks you are trying to select two things at the same time.
ddlDays.ClearSelection()
'now set the selected value by the text of the item
ddlDays.Items.FindByText("90").Selected = True

I know, it isn’t rocket science but if I don’t post it here, I will pull out my hair next time I need it!


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress and HQ Premium Themes.