Gridview - EditItemTemplate DropDownList issue
I have a gridview that includes an EditItemTemplate that uses a dropdown listbox that is bound to a dataset, instead of a textbox to get user input. When I click on the edit button I get the error message
'ddLocation' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
I have seen lots of comments on this in several onlne forums, but cannot seem to get it right. What code behind event would i use to check the dropdown list and place a default value to get around this issue? I included my asp code below.
<asp:AccessDataSource ID="dsLocations" runat="server" DataFile="~/App_Data/Corporate.mdb"
SelectCommand="SELECT [City] FROM [tblStores] ORDER BY [City]" ></asp:AccessDataSource>
<asp:DropDownList ID="ddLocation" runat="server" DataSourceID="dsLocations" DataTextField="City"
DataValueField="City" Width="192px" DataMember="DefaultView" SelectedValue='<%# Bind("Location") %>'>
<asp:Label ID="lblLocation" runat="server" Text='<%# Bind("Location") %>' Width="128px"></asp:Label>