.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 - .SelectedValue Not Changing

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


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&

View Complete Post

More Related Resource Links

Radiobuttonlist SelectedIndexChanged When Changing dropdownlist



I have a radiobutton list that changes the contents of a dropdownlist when the selected radiobuttonlist index is changed using the SelectedIndexChanged event. Both controls are within the same updatepanel and both have autopostback set to true.

For some reason when I change the dropdownlist and cause a postback, the radiobuttonlist change event fires and repopulates the dropdownlist which effectively cancels the selection made in the dropdown.

I know something simple must be causing this behaviour but I cannot think what and my debugging efforts are not shedding any light thus far. I have tried putting a breakpoint on every procedure in my form and the first event that fires is the radiobuttonlist SelectedIndexChanged event so nothing in my server side code seems to be doing this which suggests it is something in the markup but I can't think what. 

Does anyone have any idea what may be causing this infuriating but obviously simple problem?



'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 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

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

DropDownList in DetailsView, invalid SelectedValue


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

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?



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

Changing the graphics on the home page of a SharePoint site

When you create a site in Microsoft Windows SharePoint Services by using the default Team Site template, the home page includes two default graphics. A Windows SharePoint Services graphic appears in the body of the page, and a picture of a house in a circle appears near the site title. You can change these graphics to customize your site. Changing the smaller graphic requires a Windows SharePoint Services compatible Web page editor

jQuery: Styling DropDownList Alternating Items (Rows)

In the following example, I will show how you can style any asp:dropdownlist very easily.

The example demonstrates how you can change alternating row items background color, using the fadeTo() to add a nice touch in the dropdownlist. You can change alt rows with a couple lines.

Working with DropDownList and ListBox Controls in ASP.NET

"In my application i am using dropdownlist to display all categories from a table. When the user clicks this control I display all records in that category. Category table also contains column called color.

I wanted display some categories in dropdown list different color and others in different color using ASP.NET."-Anonymous

ASP.NET DropDownList Web Control, Part 1

Anybody with much experience in ASP has written an include file function for populating the contents of a SELECT dropdown list with entries from a database. Some of the more advanced users have even gone so far as to add caching to their function to reduce database hits for these rarely changing menu options. Naturally, these same techniques are going to be used with ASP.NET, but with a new programming object model. ASP.NET provides a web control, the DropDownList, which can be used for the same purposes as our custom built SELECT tag from Classic ASP.

Declaring a DropDownList in ASP .Net

A DropDownList is also commonly known as combo box. It can contain multiple data members, but unlike a normal list box the users can choose only one value from this control. Though the functionality of this DropDownList is much like a Single Row Select List Box, a DropDownList can save a lot of GUI space as it is rendered on a Single line and is expanded only when the user clicks on the Control

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.

ASP.NET Multiple Selection DropDownList with AJAX HoverMenuExtender

Recently, I was looking for a multiple selection dropdownlist control for my new project. After spending some time researching for it, I decided to put together all my finding in one web user control. This web user control consists of an ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet and CheckBoxListExCtrl . The final product will work with or without a MasterPage and you can drag and drop more than one instances of the control on to the page.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.
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