SelectedValue 无效,因为它不存在于项目列表中
我反复遇到这个问题,但不知道是什么原因造成的。我在 DataBind 中遇到异常:
"SelectedValue which is invalid because it does not exist in the list of items"
以下是一些重要的信息:
- 当基础数据发生更改时,我会定期重新加载 listOrgs。
- Organization.DTListAll 调用返回大约 500 个 Int、String 对。
- 返回的数据中没有重复值或空值
- 下面前两行之后,listOrgs.Items.Count 为 0,Selected Value 为 0
- DataBind 操作执行时选择的值不在集合中返回的 ID 值
listOrgs.Items.Clear();
listOrgs.SelectedValue = "0";
listOrgs.DataSource = new Organization().DTListAll(SiteID);
listOrgs.DataTextField = "OrganizationName";
listOrgs.DataValueField = "OrganizationID";
listOrgs.DataBind();
I encountered this problem repeatedly, and haven't a clue what is causing it. I get an exception in the DataBind:
"SelectedValue which is invalid because it does not exist in the list of items"
Here are some important pieces of information:
- I reload listOrgs periodically when the underlying data has changed.
- The Organization.DTListAll call returns about 500 Int, String pairs.
- There are no duplicate or null values in the returned data
- After the first two lines below, listOrgs.Items.Count is 0, and the Selected Value is 0
- The selected value when the DataBind operation executes is a value that is not in the set of ID values returned
listOrgs.Items.Clear();
listOrgs.SelectedValue = "0";
listOrgs.DataSource = new Organization().DTListAll(SiteID);
listOrgs.DataTextField = "OrganizationName";
listOrgs.DataValueField = "OrganizationID";
listOrgs.DataBind();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查现有值
除此之外 - 您可能想在绑定之前尝试设置数据文本和数据值字段(据我所知,这是性能++)
Check for an existing value
Besides that - you might want to try to set the datatext and datavalue fields before you bind (afaik that is a performance++)