Before setting the selected value, check whether the item is in the list and what it is selected by index
<asp:DropDownList id="dropDownList"
AutoPostBack="True"
OnDataBound="OnListDataBound"
runat="server />
protected void OnListDataBound(object sender, EventArgs e)
{
int itemIndex = dropDownList.Items.IndexOf(itemToSelect);
if (itemIndex >= 0)
{
dropDownList.SelectedItemIndex = itemIndex;
}
}
EDIT: Added ...
If you are linking to the Load page, try to follow this path:
- Move all binding related code in overriden method
DataBind() - Page_Load : ( DataBind , )
if (!IsPostBack)
{
Page.DataBind();
}