?
Solved

Gridview EditItemTemplate DropDownList Binding Issue in ASP.net 2.0

Posted on 2007-07-25
5
Medium Priority
?
456 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:Artform04
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:PHD
ID: 19566197
Are you sure that all value in the database are included in the values of the dropdownlist ?
0
 
LVL 1

Author Comment

by:Artform04
ID: 19566572
well, using the visualiser for the datasource in visual studio 2005, i tested the query and all the data came out perfect...?
0
 
LVL 6

Accepted Solution

by:
PHD earned 1500 total points
ID: 19567663

If you query the database with this select : select distinct UnitTypeId from tblUnitType
All the UnitTypedId of the result are values of the dropdownlist.

This Just to be sure that the all values UnitTypeId of the datasource match a value in the dropdownlist otherwise the dropdownlist.selectedvalue cannot be bound.

the error occur when the gridview is in read mode ?
0
 
LVL 1

Author Comment

by:Artform04
ID: 19615855
I have solved the problem, nothing to do with read mode, but congrats... as u tried, you get 500 points!!
0
 
LVL 6

Expert Comment

by:PHD
ID: 19615877
thank you
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question