Skip to content
Advertisement

DropDownList has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

I keep getting the above error in the title line and it makes no sense, because I am using a sample table with only 5 records and each record has a value as per the drop down menu.

This is my code used to declare the drop down list. I have joined two tables in my SQL data source to reflect what I want populated in the grid view and have hidden columns as necessary. I am using the same data source to populate the drop down list any help would be most appreciated

enter image description here

Advertisement

Answer

Attempt to find the value in the drop down list before attempting to set the SelectedValue, like this:

Note: The Trim() call will remove any leading or trailing spaces in your text box text, which could be a cause for a match not being found.

So your full code should be this:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement