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

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

问题描述

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

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

 < ASP:DropDownList的ID =_ ddlRequests=服务器AppendDataBoundItems =真DataTextField =RequestNumberDataValueField =RequestNumber>
    < ASP:ListItem的文本=VALUE =/>
< / ASP:DropDownList的>


解决方案

这可能是值得先绑定,然后添加你的空白值。沿着线的东西:

  _ddlRequest.Datasource =请求;
_ddlRequest.DataBind();
_ddlRequest.Insert(0,新的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&QUOT;拥有的SelectedValue,因为它不中的项目&QUOT列表存在这是无效的;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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