2

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I realised I had missed that off just before checking the post. This was the problem. Thank you
0

One workaround could be.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.