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.
Your markup says you are binding the
SelectedValueof yourDropdownListto the “Province” field in your parent datasource (the datasource for theGridview)The values in your
DropDownListare coming from the “ProvinceName” field in yourAccessDataSource4control.This error means that your code is selecting a value from the
GridViewdatasource (“Province” field) that does not exists in the list of values returned in the “ProvinceName” field of yourAccessDataSource4control.A quick solution to this would be to modify the “SelectCommand” of
AccessDatasource4so that it runs the same query as yourGridViewcontrol’s datasource, but with only the one column you need (“ProvinceName”) in theSELECTlist. That way you are guaranteed to have the same values.