处理下拉列表中的空值 [英] Handle Nulls in Dropdown Lists
问题描述
我的代码中显然存在nulls或其他问题。代码是:
I apparently have an issue with nulls, or something else, in my code. The code is:
代码开始
asp:DropDownList ID =" ddlCity" RUNAT = QUOT;服务器"的DataSourceID = QUOT; dsPatientDemosCity" DataTextField = QUOT;城市" DataValueField = QUOT;城市" SelectedValue ='<%#Bind(" City")%>'>
asp:DropDownList ID="ddlCity" runat="server" DataSourceID="dsPatientDemosCity" DataTextField="City" DataValueField="City" SelectedValue='<%# Bind("City") %>'>
END OF CODE
我收到以下错误:
'ddlCity'有一个SelectedValue无效,因为它在项目列表中不存在。
参数名称:值
'ddlCity' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
如何解决这个问题?
谢谢。
推荐答案
你有一个名为
City 的变量,它将保留所选的值?
Do you have a variable called City which will hold the selected value?
尝试在forums.asp.net上询问,其中有一些观众熟悉这些问题。例如,检查为初始状态添加
AppendDataBoundItems 属性和特殊列表项("请选择")的解决方案:
https://forums.asp.net/t/1056921.aspx 。
Try asking at forums.asp.net, which has an audience familiar with such problems. For example, check a solution that adds the AppendDataBoundItems attribute and a special list item ("Please select") for initial state: https://forums.asp.net/t/1056921.aspx.
这篇关于处理下拉列表中的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!