.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

Radiobuttonlist SelectedIndexChanged When Changing dropdownlist

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


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?



View Complete Post

More Related Resource Links

Dropdownlist not firing SelectedIndexChanged on first item with autopostback true

Hi: Has anyone ever found a work around for the well documented and well known bug, the dropdownlist bug? Specifically where the SelectedIndexChange event does not fire on the first listitem, althought both autopostback and enableviewstate are true? In other words, if the first three items in the dropdownlist are red, blue, green, if you select green, the SelectedIndexChanged will fire, but if you then select red, the first item in the ddl, the event will not fire. All listitems will fire the SelectedIndexChanged event, except for the very first listitem. The HACK has always been to include a dummy item as the first list time like"Select a Color" to get around the first item bug. I have got a situation where I cannot use that hack. Ideas?  TIA, Bill  

Strange connection between ViewState and DropDownList's SelectedIndexChanged event


So, I have this code (just for example):

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Sort by:"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            <asp:ListItem Value="A" Text="A"></asp:ListItem>
            <asp:ListItem Value="B" Text="B"></asp:ListItem>
            <asp:ListItem Value="C" Text="C"></asp:ListItem>
            <asp:ListItem Value="D" Text="D"></asp:ListItem>
        <asp:GridView ID="GridView1" runat="server" onsorting="GridView1_Sorting">

The Code-behind file looks like that:

public partial class _Default : Syst

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&

Dropdownlist in a repeater firing the SelectedIndexChanged event


I have a dropdownlist in a repeater and it's firing the SelectedIndexChanged event but in teh event handler I can not get the dataitem associated with the row that the DDL is in.  Here is the code:

        private void pt_SelectedIndexChanged(object sender, EventArgs e)
            DropDownList ddl = (DropDownList)sender;
            RepeaterItem ri = (RepeaterItem)ddl.NamingContainer;
            int userdevi

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.SelectedIndexChanged not working



I have the following in a web user control:


asp:DropDownList ID="ddlPrescriptionCodeGroup" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID

Update databse with DropDownList in GridView, SelectedIndexChanged


I am new to asp.net (I may use some incorrect termology while I explain my issue...) and need some help with DropDownList in Gridview.  Currently I have a GridView set up with three Columns bound to a database: Column1 - some kinda of index, Column2 - string, Column3 - DropDownList(called Active).  So far when I build the page, all the columns show up and the DropDownList appears and the values are bound correctly.  I want to change a value in the DropDownList and automatically update that value in my database. 

I have set AutoPostBack = true and I made a DataObject (called UpdateActive) to update the database (it takes 2 inputs, the Column1 index and Column3 DropDownList value).  However, I don't know how to find the row that I am changing, is there a way to figure out what row it is (like finding the Column 1 index?).  Also, I don't want to have to click a button to update the data.

                        <asp:GridView ID="gvWorkflowStepOrder" runat="server" AllowPaging="True" AllowSorting="true"
AutoGenerateColumns="False" DataKeyNames="WorkflowStepOrderID" PageSize="50"

Confirm DropDownList SelectedIndexChanged



I want to check something with the users before they change the selectedvalue of a dropdownlist (DDL).

I use codebehind:

protected void ddlZavarovatelj_PreRender(object sender, EventArgs e)
            DropDownList ddl = (DropDownList)detailsview1.FindControl("ddlZavarovatelj");
            ddl.Attributes.Add("onchange", "return window.confirm('Are you sure?');");

Why if the user clicks "No" the selectedvalue still get's changed? Also why if the user clicks "Yes" the code from DDL's OnSelectedIndexChanged is not fired??



Disabling ViewState for DropDownList and using AutoPostback with SelectedIndexChanged


The sites I mantain are using way too much ViewState and I'd like to reduce that so the size of the page is reduced.  I've done a lot to remedy this but I have an issue relating to DropDown lists that use AutoPostbacks.

I have a dropdown list with a lot of list items and a good part of the ViewState usage is to hold the list item data.  If I disable ViewState and set the AutoPostBack property to true, the page will post back and in the page load I am trying to repopulate the dropdown list with cached data.  However, it seems that the SelectedIndexChanged event doesn't fire when EnableViewState="false".

Is it possible to make this work without enabling ViewState for the drodown list?

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