dropdown list problem formview asp.net 2.0

Posted on 2006-04-10
Medium Priority
Last Modified: 2008-05-19
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">
                    <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
  • 4
  • 3

Expert Comment

ID: 16417390
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.  

Accepted Solution

ptleitch earned 2000 total points
ID: 16417523
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

ID: 16417894
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>
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

ID: 16418031
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

ID: 16418496
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.

Expert Comment

ID: 16430160
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

ID: 16439930
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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

840 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