dropdown list problem formview 2.0

Posted on 2006-04-10
Last Modified: 2008-05-19
Hi there,

The problem i am having is getting dropdownlists to work in templates within formview 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">
                    <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Salutation") %>'>
                    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DeleteMethod="Delete"
                        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataSaluation"
                        TypeName="HCDataSetTableAdapters.HCSaluationTableAdapter" UpdateMethod="Update">
                            <asp:Parameter Name="Original_SalutationID" Type="Int32" />
                            <asp:Parameter Name="Salutation" Type="String" />
                            <asp:Parameter Name="Original_SalutationID" Type="Int32" />
                            <asp:Parameter Name="SalutationID" Type="Int32" />
                            <asp:Parameter Name="Salutation" Type="String" />

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

Question by:sunny-j
    LVL 3

    Expert Comment

    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.  
    LVL 3

    Accepted Solution

    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.

    Author Comment

    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.


    <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Salutation") %>' OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True" Width="140px">
                            <asp:ListItem Selected="True">Mr</asp:ListItem>
    LVL 3

    Expert Comment

    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.

    Author Comment

    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.
    LVL 3

    Expert Comment

    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:




    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.

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now