views:

234

answers:

2

Hi,

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

A: 

Try adding AppendDataBoundItems="true" to the DropDownList as one if its properties. See http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx

Dan Diplo
I realised I had missed that off just before checking the post. This was the problem.Thank you
anD666
A: 

One workaround could be.

Try to assign Selected value in code behind. There you can check for null value easily.

Saar