1

I have a DropDownList in GridView. During the edit action, DropDownLists in all the rows work properly on editing (and updating).

But in certain rows, when I click edit button, it displays the following error:

'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

This is the code:

<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="AccessDataSource4"
    DataTextField="ProvinceName" DataValueField="ProvinceName" SelectedValue='<%# Bind("Province") %>'>
</asp:DropDownList>

Table "RateCenters" is displayed in the Gridview, which has "Province Column". Province column gets the source from the "ProvinceName" of the Table ProvinceList.

Kindly let me know the solution.

4
  • You need to show your DropDownList markup. Commented Feb 27, 2012 at 14:40
  • We need to see the way you're databindind your DropDownList. Apparently you're setting it's SelectedValue to somewhat not existing. Commented Feb 27, 2012 at 14:43
  • @TimSchmelter I have added the markup Commented Feb 27, 2012 at 14:50
  • @jadarnel27 I have added the markup Commented Feb 27, 2012 at 14:51

2 Answers 2

2

Your markup says you are binding the SelectedValue of your DropdownList to the "Province" field in your parent datasource (the datasource for the Gridview)

The values in your DropDownList are coming from the "ProvinceName" field in your AccessDataSource4 control.

This error means that your code is selecting a value from the GridView datasource ("Province" field) that does not exists in the list of values returned in the "ProvinceName" field of your AccessDataSource4 control.


A quick solution to this would be to modify the "SelectCommand" of AccessDatasource4 so that it runs the same query as your GridView control's datasource, but with only the one column you need ("ProvinceName") in the SELECT list. That way you are guaranteed to have the same values.

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

Comments

1

If you programatically set a value in DDL (DropDownList) that actually does not exist in the list, you will get this error.

Scenario: You selection option 5 in DDL, but it contains only 3 options, for example

Tell use a little more about your code so we can investigate.

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.