web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / “DropDownList has a Selecte...

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

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

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.


Filed under: ASP.NET, C# Tagged: ASP.NET

This was originally posted here.

Comments

*This post is locked for comments