Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 5th, 2006, 03:51 PM
Registered User
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default DropDownList SelectedIndexChanged Event does not

DropDownList SelectedIndexChanged Event does not fire and when selecting a new item the dropdown reverts back to 0 (first item). I have a very simple Web form with two drop down controls. The first drop down works okay. It gets all of the major categories from the SQl Express database and the SelectedIndexChanged Event does fire (even though I don't need to do anything in this event). The second DropDownList control populates okay using the First DropDownList SelectedValue, but when You try to select an item, the SelectedIndexChanged event does not fire and the DropDownList index reverts to 0. I have included both the source and code behind ... I hope someone can help ... fighting this for over a day.
(DropDownList2 is the one I am having problems with):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AdminBusCustomerData2.aspx.vb" Inherits="AdminBusCustomerData2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <table style="width: 90%">
                <td style="width: 100px">
                <td style="width: 100px">
                    <br />
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                        DataTextField="BusCatName" DataValueField="BusCatID">
                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        SelectCommand="SELECT [BusCatID], [BusCatName] FROM [BusCategory]"></asp:SqlDataSource>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
                <td style="width: 100px">
                <td style="width: 100px">
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
                        DataTextField="BusSubCatName" DataValueField="BusSubCatId">
                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        SelectCommand="SELECT [BusSubCatId], [BusSubCatName] FROM [BusSubCategory] WHERE ([BusSubCatId] = @BusSubCatId)">
                            <asp:ControlParameter ControlID="DropDownList1" Name="BusSubCatId" PropertyName="SelectedValue"
                                Type="Int32" />
                    <br />
                    &nbsp;<asp:Button ID="Button1" runat="server" Enabled="False" Text="Button" Width="128px" /></td>
                <td style="width: 100px">


... and the code behind which is doing very little:
Partial Class AdminBusCustomerData2
    Inherits System.Web.UI.Page

    Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        Button1.Enabled = True
        Dim BusCatSubIdvar As String = DropDownList2.SelectedItem.Text
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

    End Sub
End Class

Old November 6th, 2006, 08:52 PM
Authorized User
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts

Hmm, I see your methods for the index change but I do not see them in the asp code. Where is the field for both drop downs for "SelectedIndexChanged"? Somewhere should read SelectedIndexChanged or OnSelectedIndexChanged= and then the method name. Not near my VS computer but that is what you are missing. :) If you use Visual Studio. Select the drop down and under properties select the lightning both that selects the events. Select the index changed even and type/select the method to call for the event. Do that for each. :)

Old November 6th, 2006, 09:37 PM
Authorized User
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts

plz mention clearly what u wanna do on selection of a value in drpdownlst1, and then what u wanna do on selection of a value in dropdwnlst2. also state why have u have used the control parameter for drpdwnlst2 ??? only then can help u effectively.

therez nothin' as impossible, bcaz the word itself says : 'i'-'m'-'possible'
Old October 12th, 2007, 10:20 AM
Registered User
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

I'm having the same problem right now. Everytime I select anything from the dropdownlist, the selectedvalue always becomes the value of the first item.

I'm trying to fix it, but in the meantime, if somebody can help, it would be great.

Btw, I'm using ASP.NET AJAX and my ddl is in a user control, which is located inside Accordion from Ajax Toolkit.

EDIT: Just added a if(!IsPostBack) then populate ddl, it worked fine. Such a simple mistake, and I was wondering around for two hours! :(

Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist on selectedindexchanged RoniR ASP.NET 1.x and 2.0 Application Design 4 April 6th, 2012 04:50 PM
Problem with Dropdownlist.SelectedIndexChanged haydar BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 July 20th, 2007 10:26 AM
DropDownList SelectedIndexChanged problem p_heidi ASP.NET 1.0 and 1.1 Basics 3 April 27th, 2006 10:20 AM
Listbox selectedindexchanged event venterjo General .NET 6 December 9th, 2004 08:46 AM
listbox event SelectedIndexChanged alyeng2000 ASP.NET 1.0 and 1.1 Basics 2 December 22nd, 2003 10:50 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.