Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 December 5th, 2005, 05:09 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default Raise Event for Dynamically Added DropDownList

Good afternoon to all,

Since I seemed to have stumped the experts on here as to how to go about creating a "chain" of dropdownlists, I was hoping someone could help me with a smaller issue. How would I go about raising an event for a particular dropdownlist when multiple dropdownlists are being added to a webform dynamically. Please see my code below.

For Each dr In ds.Tables("options").Rows
   Dim ddl As New DropDownList
   ddl.ID = dr("styleOpt_title")
   ddl.AutoPostBack = True
   styleData_optionBasket.Controls.Add(ddl)

    AddHandler ddl.SelectedIndexChanged, AddressOf ddl_SelectedIndexChanged

    ddl.Items.Insert(0, New ListItem("Please select..."))
Next


As I could potentially be adding upward of 4 DropDownLists to a form, how could I raise an event for the, let's say, 3rd DropDown. Right now, when I call the ddl_selectedIndexChanged event, the values from all of the dropdownlists are being captured.

Thank you and I hope someone can lend some much needed assistance.

Regards.
 
Old December 6th, 2005, 12:41 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

What is the code in the handler? It should only trap the value from the dropdown list being changed. I have done this in the past with no problems. Let's see the handler code.

Jim

 
Old December 6th, 2005, 01:02 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

Jim,

Thanks for the reply. I am not doing anything fancy, that is until I can get it to work <smile>. The following is the basic handler... something to just test for the returned values.

Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
      Dim drop As DropDownList = CType(sender, DropDownList)
      lblTest.text = drop.SelectedValue.ToString
End Sub

In my test DB I have two dropdownlist's being created by the code in my original post above. I was using a simple Reponse.Write to dump the results back to the screen and was getting the values for both DropDownLists returned. Now that I have switched the results to a Label control, I am only getting the value of the second dropdownlist, regardless of changing the value in the first dropdownlist.

Ultimately, I am looking to be able to identify the different dropdownlists to pull their respective values into follow-on functions.

I can provide screen shots if you think it will be easier to visualize the problem.

AMMEDNED: Jim, Is it at all possible to create a delimited string of the returned values for all of the dropdownlists on the webform (ie. 3|12|5)

Many thanks,
Eric
 
Old December 6th, 2005, 02:22 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I think I see your problem. It is in the handler declaration:
Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged

Remove the bolded code above.

This handler will only handle the selectedindexchanged event for ddl, which I assusme is another dropdown you have definded somewhere.

Jim








Similar Threads
Thread Thread Starter Forum Replies Last Post
raise event martijn1967 C# 1 May 30th, 2007 09:16 PM
Dynamically Added Control ID changes pauliehaha ASP.NET 2.0 Basics 14 April 4th, 2007 08:56 AM
How to raise event in user control webpart... tqit ASP.NET 2.0 Basics 1 September 13th, 2006 04:37 AM
Raise Event From Dynamic Controls netwizard_01 ASP.NET 1.0 and 1.1 Basics 1 August 3rd, 2006 06:50 AM
Capturing Dynamically Added Client Values Colonel Angus ASP.NET 1.0 and 1.1 Professional 4 April 14th, 2006 12:38 PM





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