Issue with DropDownList on FormView Edit

I have a simple Gridview and Formview set up on a couple of different pages. I use the FormView to edit existing records in the GridView or to add a new record. It works perfectly on one page, but on another one when I select the record in the Gridview that I want to edit in the FormView, I keep getting this error message:
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Open in new window

I can run SELECT DISTINCT WHS FROM AER_DOCK_APPOINTMENTS and I get three returned entries, each two characters long. In the DropDownList on the page, I have those same three two-character long choices as ListItems. The Insert from the FormView works perfectly.

CODE FOR DROPDOWN ON PAGE THAT WORKS
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("WAREHOUSE") %>'>
                                <asp:ListItem Selected="True"></asp:ListItem>
                                <asp:ListItem>LB</asp:ListItem>
                                <asp:ListItem>LP</asp:ListItem>
                                <asp:ListItem>SN</asp:ListItem>
                                <asp:ListItem>SS</asp:ListItem>
                                <asp:ListItem>WA</asp:ListItem>
                            </asp:DropDownList>

Open in new window


CODE FOR DROPDOWN ON PAGE THAT DOES NOT WORK
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("WHS") %>'>
                                <asp:ListItem Selected="True"></asp:ListItem>
                                <asp:ListItem>LB</asp:ListItem>
                                <asp:ListItem>SN</asp:ListItem>
                                <asp:ListItem>SS</asp:ListItem>
                            </asp:DropDownList>

Open in new window


What am I missing to figure this out?
Carla RomereDirector of Information TechnologyAsked:
Who is Participating?
 
Carla RomereConnect With a Mentor Director of Information TechnologyAuthor Commented:
I changed the field definition from nchar(2) to char(2) and that resolved the problem.
0
 
Ryan ChongCommented:
do you have a field called as "WHS"?

you probably should use <%# Bind("WAREHOUSE") %> as well
0
 
Carla RomereDirector of Information TechnologyAuthor Commented:
In one table, the field is called WHS (this is the one that does not edit, but will insert successfully). The other one that works for edit and insert is called WAREHOUSE. They are two separate tables.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Ryan ChongCommented:
just a quick suggestion...

do you think can set the selected item/ value via Code Behind instead?
0
 
Carla RomereDirector of Information TechnologyAuthor Commented:
That defeats the purpose of using the GridView and FormView. It doesn't make any sense to me that one works and the other one doesn't when they are set up identically.
0
 
Ryan ChongCommented:
I changed the field definition from nchar(2) to char(2) and that resolved the problem.
Ok.... but seems a weird solution for me, but glad you found a way out.
0
 
Carla RomereDirector of Information TechnologyAuthor Commented:
I read somewhere that "nchar" sometimes adds invisible characters or something. I thought it was odd too.
0
 
Carla RomereDirector of Information TechnologyAuthor Commented:
It was the only solution that worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.