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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
just a quick suggestion...

do you think can set the selected item/ value via Code Behind instead?
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

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
Carla RomereDirector of Information TechnologyAuthor Commented:
I changed the field definition from nchar(2) to char(2) and that resolved the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.