DropDownList中具有的SelectedValue这是无效的,因为它不会在项目列表中存在 [英] DropDownList has a SelectedValue which is invalid because it does not exist in the list of items

查看:551
本文介绍了DropDownList中具有的SelectedValue这是无效的,因为它不会在项目列表中存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情况:

在DropDownList中的选择是从数据库表列出了可接受值的约束。在一个时间点上的值分别为:

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

然而,在仍然存储的下拉的值DB中的字段包含的三的一些行的值。当加载这些行之一,并设置的SelectedValue这样:

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"

...抛出一个错误,指出:DD拥有的SelectedValue,因为它不在项目列表中存在哪些是无效的。

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

推荐答案

我们在这里做的有这种情况。

We do have this kind of situation here.

当发生这种情况,我手动缺少的项目添加到DropDownList的,但在一个红色字体。

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.

这篇关于DropDownList中具有的SelectedValue这是无效的,因为它不会在项目列表中存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆