troubleshooting Question

Gridview EditItemTemplate DropDownList Binding Issue in ASP.net 2.0

Avatar of Artform04
Artform04 asked on
.NET ProgrammingASP.NET
5 Comments1 Solution480 ViewsLast Modified:
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

ASPX CODE:
<EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsUnitTypeAndId"
                            DataTextField="Name" DataValueField="UnitTypeId" SelectedValue='<%# Bind("UnitType") %>'>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="dsUnitTypeAndId" runat="server" ConnectionString="<%$ ConnectionStrings:SmartEstateManagementConnectionString %>"
                            SelectCommand="SELECT [UnitTypeId], [Name] FROM [tblUnitType]">
                        </asp:SqlDataSource>
                    </EditItemTemplate>


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.

Thanks, Phil

PS. THERE ARE NO NULL VALUES RETURNED IN THE DATASOURCE
ASKER CERTIFIED SOLUTION
PHD

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros