SqlDataSource 中出现空值的 ASP.NET 下拉列表错误
我在表单视图上有一个下拉列表,它们都绑定到不同的数据源。
当尝试运行该程序时,我收到“ddlFieldName”有一个无效的 SelectedValue,因为它不存在于项目列表中。参数名称:值。
我认为这是因为与下拉列表关联的字段包含引用表中不存在的空值。我试图通过在列表中添加一个空项目来解决这个问题,但它似乎不起作用:
<asp:DropDownList ID="ddlAgency" runat="server"
DataSourceID="dsAgency" DataTextField="Agency"
DataValueField="AgencyID" SelectedValue='<%# Bind("Agency") %>' >
<asp:ListItem></asp:ListItem></asp:DropDownList>
任何人都可以建议解决这个问题的方法吗?
谢谢
D666
I have a drop down list on a form view which are both bound to different data sources.
When trying to run the program I am getting 'ddlFieldName' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value.
I think it is because the field associated with the drop down list contains a null value which isnt in the referencing table. I have tried to work round this by adding an empty item in the list but it doesnt seem to be working:
<asp:DropDownList ID="ddlAgency" runat="server"
DataSourceID="dsAgency" DataTextField="Agency"
DataValueField="AgencyID" SelectedValue='<%# Bind("Agency") %>' >
<asp:ListItem></asp:ListItem></asp:DropDownList>
Can anyone suggest a way round this?
Thanks
anD666
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
AppendDataBoundItems="true"
添加到 DropDownList 作为其属性之一。请参阅http://weblogs.asp.net/scottgu/archive /2006/01/29/436804.aspxTry adding
AppendDataBoundItems="true"
to the DropDownList as one if its properties. See http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx一种解决方法可能是。
尝试在后面的代码中分配选定的值。在那里您可以轻松检查空值。
One workaround could be.
Try to assign Selected value in code behind. There you can check for null value easily.