Quantcast
Viewing latest article 40
Browse Latest Browse All 41

“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.


Viewing latest article 40
Browse Latest Browse All 41

Trending Articles