Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 5th, 2006, 03:51 PM
Registered User
Join Date: Oct 2006
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old November 6th, 2006, 08:52 PM
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2005
Location: Fresno, California, USA.
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. :)

Reply With Quote
  #3 (permalink)  
Old November 6th, 2006, 09:37 PM
Authorized User
Join Date: Sep 2006
Location: mumbai, maharashtra, India.
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'
Reply With Quote
  #4 (permalink)  
Old October 12th, 2007, 10:20 AM
Registered User
Join Date: Oct 2007
Location: , , .
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! :(
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 10:37 PM.

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