DropDownList“具有无效的SelectedValue,因为它不存在于项列表” [英] DropDownList "has a SelectedValue which is invalid because it does not exist in the list of items"

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

问题描述

我有一个ASP.NET DropDownList,我将数据绑定到一个对象列表,然后它抛出一个异常。这个错误让我很坚强,因为消息是错误的,清单中的值存在于项目列表中,如屏幕截图所示:



以下是相关的ASP.NET标记:

 < asp:DropDownList ID =_ ddlRequestsrunat =serverAppendDataBoundItems =trueDataTextField =RequestNumberDataValueField =RequestNumber> ; 
< asp:ListItem Text =Value =/>
< / asp:DropDownList>


解决方案

这可能值得首先进行数据绑定,然后添加您的空白值。以下行:

  _ddlRequest.Datasource = request; 
_ddlRequest.DataBind();
_ddlRequest.Insert(0,new ListItem(,));

我建议这样做的唯一原因是我在遇到挫折之前和之后遇到这个问题一段时间刚刚解决了这样做。


I have a ASP.NET DropDownList, which I data-bind to a list of objects, and then it throws an exception. This error is driving me nuts, because the message is wrong, and the value clearly does exist in the list of items, as shown by the screenshot:

Here's the relevant ASP.NET markup:

<asp:DropDownList ID="_ddlRequests" runat="server" AppendDataBoundItems="true" DataTextField="RequestNumber" DataValueField="RequestNumber">
    <asp:ListItem Text="" Value="" />
</asp:DropDownList>

解决方案

It may be worth first databinding and then adding your blank value. Something along the lines of:

_ddlRequest.Datasource = request;
_ddlRequest.DataBind();
_ddlRequest.Insert(0, new ListItem("", ""));

The only reason I suggest this is that I came across this before and after banging my head in frustration for a while just settled on doing it this way instead.

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

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