“DropDownList has a SelectedIndex which is invalid because it does not exist in the list of items” error while setting SelectedIndex

I had my drop down list defined as following
<asp:DropDownList
ID=”ddlNeedEFMP” runat=”server” Enabled=”False”>
<asp:ListItem
Value=”2″>No</asp:ListItem>
<asp:ListItem
Value=”1″>Yes</asp:ListItem>

</asp:DropDownList>
To set it’s selectedindex we can make use of below syntax.

ddlNeedEFMP.SelectedIndex= ddlNeedEFMP.Items.IndexOf(ddlNeedEFMP.Items.FindByValue(“1”));

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s