cardiffcoder
My favourite mistake, databinding too early.

If there is one mistake I make almost every single time when working with webforms it is this one, databinding controls during the OnLoad event. This is particularly perilous for DropDownLists and RadioButtonLists and I’ll tell you why …

OnLoad is fired very early on in the ASP.NET page lifecycle and what this does is wipe out any selections you made before postback because the control has been cleared and then re-populated, clearning SelectedValue, SelectedItem etc.

I’ve seen many different ways that people databind controls to overcome this, but the plain, simple and easiest way is to just databind later, after you have dealt with the SelectedValue or SelectedItem properties. Personally, I databind during PreRender.

Viewstate is your friend

Persisting the state of DropDownLists in ASP.NET is simpler than you think.
A lot of people will go the way of storing the SelectedIndex in a Session variable on postback then retrieving it and setting the SelectedIndex again on Load - but this is all unnecessary in most circumstances.

If you simply want to set the SelectedValue to be what it was before a PostBack, simply use the EnableViewState options at both Page and Control level.

EnableViewState=”true” in your <@Page attribute at the top of the web form and EnableViewState=”true” in the <ASP:DropDownList control.

And that’s it. No faffing around in the code-behind, trying to grab the SelectedIndex before it gets wiped out by the Page_Load or setting it after the DataBind. Simple as.