Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Here's the scenario:

The selections in DropDownList are bound from a DB Table listing the acceptable values. At one point in time the values were:

One Two Three Four

At some point later, the list of acceptable values change to:

One Two Four Five

However, the field in the DB that stores the dropdown's value still contains a value of "Three" on some rows. When loading one of those row and setting SelectedValue as such:

dd.SelectedValue = data.Field; // where data.Field == "Three"

...an error is thrown stating: 'dd' has a SelectedValue which is invalid because it does not exist in the list of items.

Data clean up isn't an option here. It would cause problems for customers as the stored values aren't invalid choices for data that's already created, but are invalid choices for newly created data.

How have others handled this situation?

like image 918
Craig M Avatar asked Dec 18 '25 22:12

Craig M


1 Answers

We do have this kind of situation here.

When that happens, I manually add the missing item to the dropdownlist, but in a red font.

If the user tries to re-save the item, the red items are considered inactives and invalid. A valid choice (non-red) must then be picked from the drop-down list.

like image 135
Danny T. Avatar answered Dec 20 '25 15:12

Danny T.