dropdown list problem formview asp.net 2.0

Hi there,

The problem i am having is getting dropdownlists to work in templates within formview asp.net 2.0


This error occurs when i have attempt to bind the control (usually dropdownlist control) within the edit item template.

hThis is a typical error.
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Here is the code.

<asp:TemplateField HeaderText="Salutation" SortExpression="Salutation">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Salutation") %>'>
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DeleteMethod="Delete"
                        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataSaluation"
                        TypeName="HCDataSetTableAdapters.HCSaluationTableAdapter" UpdateMethod="Update">
                        <DeleteParameters>
                            <asp:Parameter Name="Original_SalutationID" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="Salutation" Type="String" />
                            <asp:Parameter Name="Original_SalutationID" Type="Int32" />
                            <asp:Parameter Name="SalutationID" Type="Int32" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:Parameter Name="Salutation" Type="String" />
                        </InsertParameters>
                    </asp:ObjectDataSource>
                </EditItemTemplate>

Please tell me if you spot something that requires changing or whether there is a better way to do this. Thanks.

sunny-jAsked:
Who is Participating?
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.

ptleitchCommented:
you are getting this error because your database has a null value and doesn't know where to assign it in the drop down list.  You probably need to add and empty <listitem></listitem> that the null value will associate with.  
0
ptleitchCommented:
well it doesn't look like you have any list items in the code above, in which case even if you database value isn't null, it would have trouble associating with the list items because, "because it does not exist in the list of items"  you need to have list items that match those in your database.
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
sunny-jAuthor Commented:
Hi, thanks for you speedy response. I have added as suggusted. I previously was pulling in the list from another table but have reverted to just specifying the listitems in the collection. Is this correct? I am getting the same error.

thanks.

<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Salutation") %>' OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True" Width="140px">
                        <asp:ListItem Selected="True">Mr</asp:ListItem>
                              <asp:ListItem>Mrs</asp:ListItem>
                        <asp:ListItem>Ms</asp:ListItem>
                        <asp:ListItem>Mr</asp:ListItem>
                        <asp:ListItem>Dr</asp:ListItem>
                        <asp:ListItem>Other</asp:ListItem>
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

ptleitchCommented:
what is it you are trying to do, insert a new record, edit an existing one, or both?  Your problem might exist from a misunderstanding of formview.
0
sunny-jAuthor Commented:
yes, it probably does to be honest. I am trying to update a record. I get to the page via a querystring from a detailsview and am then looking to update the information. thanks.
0
ptleitchCommented:
I can try helping you out a little later tonight if you still need it.  I use a drop down list successfully in formview for the selection of states.  In my DDL, i don't use:

OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

or

Selected="True"

and i can explain why later.  If you are still having problems, let me know if you would be interested in working it out later tonight, i will give you an email address that will forward 1 message to my real email account.  You can send me your email or instant messaging information there.  So niether of us has to post our real info in this forum.

Check to make sure your database values match those exactly in your edit template of formview and maybe get rid of the two things above unless you have a specific need, though you might have to use the itemcommand event for triggering events in formview.
0
sunny-jAuthor Commented:
I am impressed with the way you have answered my questions. You have answered my previous questions and i have been most impressed. You were right, i needed to understand how formview and detailview work and i have been looking at this closely. I am going to start a fresh with this and try again. I am determined to get it working. I will post a message if i get stuck again! thanks again for offering your time. Much appreciated. I will not waste your time till i am really stuck with something.
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.

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.