‘DropDownList1’ has a SelectedValue which is invalid because it does not exist in the list of items

This error is thrown by ASP.NET in a dropdownlist where the selected value (fetched from the database), does not match any of the value in the drop down list and is therefor invalid. To explain this

[csharp]

1
2
3
4

[/csharp]

Note that SelectedValue=5 does not exist in the dropdownlist therefor the error. The above code is for demenstration purpose only. It is not a working code.

Another practical example is below.

[csharp]

<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="sdsGetErrorCodes" DataValueField="ErrorID"
SelectedValue='’
DataTextField=”ErrorCode”>

[/csharp]

In the above case the SQLDataSource sdsGetErrorCodes fetches a list of error_id’s and Error_codes. If the selected one is not a match to anyone single of the one in the list, .NET would through this error.

Usually it is caused by NULL values which are not accepted in DropDownList or invalid values such as -1 etc.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s