.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DropDownList in DetailsView, invalid SelectedValue

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

I believe my question is not new here, but I think it is valuable because there are so many results from google with the 'dropdownlist in detailsview' as keywords.

Well, my question is described as below. (ASP.net and C#)

1)  I need a detailsview to add and edit record of table T1, which contains products information. T1 has a field 'catalog' which indicates the catalog of the product. All possible catalogs is stored in table T2. The simplified tables is described in 2)

2)  Simplified tables:

  • T1 fields: id, prodname,  catalog;  which is the datasource of the DetailsView.
  • T2 fields: id, catalog; which is the datasource of the dropdownlist in the detailsview.
  • all record of T1 have a catalog, which is picked up from T2.

3)  Functions I need are:

  • when detailsview in edit mode and insert mode, the field catalog should turns from a textbox to a dropdownlist which contains the catalogs stored in T2 .
  • when the item(catalog) of dropdownlist is selected and the 'update' button is clicked, the selected catalog (from T2) should replace the exist one of T1.

4)  My procedures to achieve the functions were:

  • drag and drop a detailsview control to a page, bind a datasource to it, en

    View Complete Post

More Related Resource Links

'Dropdownlist' has a SelectedValue which is invalid because it does not exist in the list of items


I have a dropdown list that has a bind on it and I get this error. Why am I getting this error and what can I do to fix it. here is the code for the dropdown I currently have:


 <asp:DropDownList  ID="DDLPreferred" AppendDataBoundItems="true" SelectedValue='<%# Bind("PREFERRED_COMMUNICATION") %>'  runat="server" TabIndex="15">
                <asp:ListItem Text="none" Value=""></asp:ListItem>

				<asp:ListItem>Home Phone</asp:ListItem>
				<asp:ListItem>Work Phone</asp:ListItem>
				<asp:ListItem>Cell Phone</asp:ListItem>


Dropdownlist error: SelectedValue which is invalid because it does not exist in the list of items.


I have a dropdownlist in a detailsview edit Item template. Also I have two tables - Employee and Main. In the Employee table I have column EmpId and AssignedTo. In the main table I have EmpId which is connected to the Employee table. 

The detailsView has a label which shows the AssignedTo name for a particular record and it works fine. But if I click the edit button to shwo the dropdownlist in the editItemTemplate it is givig me the above error.

The code is:

<asp:DetailsView ID="dtvAssign" runat="server" AutoGenerateRows

Weird problem in Detailsview - Dropdownlist in



I'm new in this forum and I really hope you'll be able to help me.

I converted a field in the detailsview into a template field and put a dropdownlist in the <InsertItemTemplate> and it worked great. This is the code I put:

<InsertItemTemplate><asp:DropDownList runat="server" DataSourceID="sdsGenresPossible" DataTextField="Genre"  DataValueField="Index" SelectedValue='<%# Bind("Genre") %>' ></asp:DropDownList></InsertItemTemplate>

Now, I tried to do the same thing for the <EditItemTemplate> . This is the code I put there:

<EditItemTemplate><asp:DropDownList runat="server" DataSourceID="sdsGenresPossible" DataTextField="Genre" DataValueField="Index" SelectedValue='<%# Bind("Genre") %>' ></asp:DropDownList></EditItemTemplate>  

When I change the DV properties I do see that a dropdownlist was  added but when I run the program and click on "Edit" in the DV nothing happens (however when I click on "Insert" it works fine).

This is the Select command for the data source I used:

<asp:SqlDataSource runat="server"

Problem binding data to DropDownList in DetailsView

Hi guys. I have a slight issue I awas trying to fix for 2-3 days, but nothing I try works. The scenario: DetailsView control in edit mode, I pass parameters to the SqlDataSourceProducts (edit.aspx?id=2) and the data source selects the appropriate data and fills in the DetailsView form. Except two drop down lists. These two DDLs (DDL2 and DDL3) are dependent on the previous DDL (DDL1) in the DetailsView. Thanks to PeteNet, when the selected value of the DDL1 changes, DDL2 and 3 change their lists and get bound to the database. The problem is: when I edit something from the database, DDL2 and 3 appear empty and when I update any other field and leave these, they get blanked in the database.  My goal is to set the selected value of DDL2 and 3 to the values in the database WHERE ID = QueryStringField="id". I can go for not binding the data unless the field is changed, but does not sound professional and user friendly. code: The SqlDataSource used to select the parameters from the table and populate the DetailsView <asp:SqlDataSource ID="SqlDataSourceProduct" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT ID, wm_number, upc, check_digit, unit, price_unit, brand, category, shelves, type, cooking, storage, packaging, origin, nutriti

Dropdownlist posted back html content,firefox alarms "Invalid postback or callback argument"


Ok probably you might have seem a dozens of post's titled "Invalid postback or callback argument" but this one is different.

Application that i am creating is simple content editor using the FCK editor.net Control (the content is HTML Encoded before saving t0 DB and then Decoded back again when displaying). just a simple drawing of of its ui is like this

DdlPages < listing the pages Whose regions/controls value can be edited> Databound

DdlRegions <listing the controls whose content can be edited> Databound on DdlPages selected index change

===========Retreived from DropDownlistRegions selected Index Change===========

txtName <a simple name for the region, user friedly identity >

==> FCK Editor <==

<Save Button> <Discard Button>


I am not such a good designer but hope you understand the UI layout.

This thing works flawless on IE 6,7,8


DropdownlistRegions holds the content to be displayed in the txtName and FckEditor. This is done by forming a custom concatenated column containing the txtName and Fckeditor(HTML content) separated by a ' ^ ' character. and then databound the column to the Dropdownlist value property.

So on selected index chang

DropDownList - .SelectedValue Not Changing



I have many dropdownlists in my application, and have never had a problem binding the data to them and setting the selectedvalue.  The ddl is in a DataGrid, and I look for the value in a label control and set the .SelectedValue to that.  I actually copied my code from a different page in my application that functions exactly the same way, except on the "original" page the .SelectedValue changes as expected.  On the "new" page I can see that the Value in the label control in the datagrid has the expected value, and as I step through the code everything is just fine until I hit the .SelectedValue = NewValue.  I can see that the current .SelectedValue is populated with the default value from the databinding, and that the NewValue has the new value I want, but after I step over that statement, the .SelectValue remains what it was as the default value.  So, here is the code:


Protected Sub dgWatchList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

Dim ddlAuditor As System.Web.UI.WebControls.DropDownList
Dim AuditorID As Integer
If e.Item.DataSetIndex >= 0 Then

            AuditorID = CType(e.Item.FindControl("lblAuditor"), Label).Text
            ddlAuditor = e.Item.FindControl("ddlAuditor&

'DropDownList6' has a SelectedValue which is invalid because it does not exist in the list of item


In my asp.net page I have a formview.  In the formview's InsertItemTemplate I declare a dropdown list as below:

                                    <asp:DropDownList ID="DropDownList6" runat="server" text='<%# Bind("District") %>'
                                    DataSourceID="SqlDataSource6" DataTextField="District"

DropDownList with CascadingDropDown no SelectedValue...?


Hi All,

I cannot get selected value from DropDownList in my codebehind, is there any possibility to get the value?

Below is which i am trying:

<asp:DropDownList id="DDL" AutoPostBack="False" runat="server">

 <cc1:CascadingDropDown ID="ccDD"

Here is my tow behind code and both are failed to get selected value.

'            With AjaxControlToolkit.CascadingDropDown
 Protected Sub FilterData()
        Dim frm As Control = Me.FindControl("searchbox").FindControl("ctl04") 'Form1 is the HTML
        For Each ctrl As Control In frm.Controls
            If TypeOf (CType(ctrl, Control)) Is AjaxControlToolkit.CascadingDropDown Then
                Dim ddl As AjaxControlToolkit.CascadingDr

Pasing Values from 1 dropdownlist to another in detailsview


Hi Guys. I have a problem I have been googling the entire day and still have no soloution. I have a detailsview with 2 dropdownlists. Fisrt one is ddlCaregory. Second is ddlSubCategory. The value is passed from the first ddl to display the SubCategory linked to ddlCategory. Both ddlCategory and ddlSubCategory are Templatefields. This is also in VB.

The Details view has a sqlDataSource (sdsApplicants), ddlCategory has a Datasource (sdsCategory) and ddlSubCategory (sdsSubCategory). ddlCategories lists the data returned from sds Categories and save any changes to sdsApplicants. I can get ddlSubCat to display the correct SubCatagory bases on ddlcategory sesection but as soon as I try bind it to sdsApplicants I get the following error

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

I will be so greatfull if someone could help me find the soloution to my problem!

can't insert from a dropdownlist within a detailsview


OK, I figure that this should be relatively straightforward, but I still can't get it to work. I have a gridview and a detailsview to set up shifts for students and teachers. I would like to be able to insert new shifts using a detailsview. I will limit the students, teachers and location to items that are in a dropdownlist. 

The problem is that when I handle the iteminserting event. the e.values collection doesn't contain all of the fields I want to populate. How do I add the new fields to the list. 

This is my codebehind:

    Sub On_Inserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
        e.Values("student") = tbStudent.SelectedValue
        e.Values("shift_location") = CType(dvNewShift.FindControl("newlocation"), DropDownList).SelectedValue

How To Do Country-State DropDownList Dependency in DetailsView Control


I have a DetailsView control in my C#/ASP.NET web application. It contains many fields, but the two I'm interested in are the Country and State fields. They are dropdownlists that display the information from the Country & State tables in the database. However, I want the State list to be filtered based on the selected Country.

I've seen many, many examples of this where the dropdownlists are outside of the detailsview controls. What I need to know is how to get it to work when these are inside of the detailsview control. I have moved the EntityDataSources for each dropdownlist outside of the detailsview control since I know that due to scope they wouldn't be able to see each other otherwise.

So, how do I make it so that when you select a country from the country dropdownlist, it auto-filters the state dropdownlist to only show the states in that country? This end of this video on ASP.NET explains how to do this outside of a DetailsView control, but not inside.


P.S. - I am using the Entity Framework / Entity Data Source for my data sources for everything.

DropDownList SelectedIndexChanged event not fired when programatically setting SelectedValue


In our asp.net web application we load the dropdown list boxes in the page load.  We than set the SelectedValue of each dropdown list box to an object from session.  We have event handlers for many of the SelectedIndexChanged events of the drop down lists boxes, but these do not get executed when we set the selected value programmatically.


Someone else mentioned this is by design, and only when a user manually changes the drop down list selected index, will the event get raised.


I would think this is a common scenario of wanting the selectedindexchanged event handled when setting the selectedvalue/selectedindex/listitem's selected property, of a DropDownList.  What is the suggested way to handle this?  Is there a significant drawback of creating a custom control inherited from DropDownList that has the functionality of raising this event when changing the SelectedIndex or SelectedValue?



Two DropDownList on one DetailsView



I have a details view which works without any problems:

<asp:detailsview id="detailsview1" runat="server" height="50px" width="550px" CellPadding="2" 
                         datakeynames="ZavPogodbaID" datasourceid="SqlDataSource1" 
                         fieldheaderstyle-width="115px" autogeneraterows="false" DefaultMode="Insert" 
            <FieldHeaderStyle Width="150px" />
                <asp:TemplateField HeaderText="Stranka:" ControlStyle-Width="400px" ControlStyle-Font-Bold="true" >
                        <asp:DropDownList ID="ddlStranka" Enabled="false" runat="server" DataSourceID="SqlDataSource3" 
                                            DataTextField="strSkrajsanNaziv" DataValueField="StrankaID" SelectedValue='<%# Bind("StrankaID") %>'>

DropDownList in DetailsView Without SQLDataSource


I am trying to use a DropDownList in a DetailsView for the ItemTemplate, InsertItemTemplate, and EditItemTemplate. I must bind this DropDownList to a SQL-Server support table using a function that returns a DataTable. I am not allowed to use a SQLDataSource in my backwards IT department. So, not only do I need to load the DropDownList, I also need to make the SelectedValue equal to the current record that I am viewing, editing. Any ideas how I do this? 

dropdownlist selectedvalue


hi All,

What is the best way to set a selectedvalue if I am working with double types

How to set the value without having comma or decimal point issues?


How to bind the selectedvalue from asp.net dropdownlist to list



Sharepoint Designer 2007:

How can i bing data from asp.net contorl dropdownlist (selectedvalue) to list.

Thank you

DropDownList, SelectedValue, From Database


I have a form, using a few DropDownLists.  The DropDownList pulls the list of items from a Table in the database. But, I would like it to select the value from the UserProfile Table, also in the database.  It populates correctly, but it is not selecting the value correctly.  The data from the UserProfile Table will be a string, not an ID column.

Here is the code I am using:



<asp:Label ID="lblSportName" runat="server" Text="Sport:"></asp:Label>
                    <asp:DropDownList ID="ddSportName" runat="server" DataSourceID="edsSports" DataTextField="SportName" DataValueField="SportID" Width="80%" ></asp:DropDownList>
                    <asp:EntityDataSource ID="edsSports" runat="server" 
                        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
                        EnableFlattening="False" EntitySetName="Sports" >


var query = (
                                                from c in context.aspnet_Users.OfType<UserProfile>()
                                                where c.UserId == _userGuid
                                                select c
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend