PROBLEM: I've creating an editItemTemplate within a gridview control. In this template, i have made a DDL which is populated from the datasource i created for that control. This datasource has two fields... the Name and the ID. I have tried to set the text on the DDL to be the name and the SelectedValue to be the ID. When I run the page i ge tthe following:
Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsUnitTypeAndId"
DataTextField="Name" DataValueField="UnitTypeId" SelectedValue='<%# Bind("UnitType") %>'>
<asp:SqlDataSource ID="dsUnitTypeAndId" runat="server" ConnectionString="<%$ ConnectionStrings:SmartEstateManagementConnectionString %>"
SelectCommand="SELECT [UnitTypeId], [Name] FROM [tblUnitType]">
I have tried different combo's of the UnitTypeId And Name being assigned to the DATAVALUEFIELD AND DATATEXTFIELD. Everything works except the combination I need which is the Id as the VALUE and the Name as the TEXT.
If anyone has any suggestions, your help would be much appreciated.
PS. THERE ARE NO NULL VALUES RETURNED IN THE DATASOURCE