开发者

ASP.NET Drop Down List error with null values in SqlDataSource

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 th开发者_如何学运维e 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


Try 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜