Wrox Programmer Forums
|
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 October 17th, 2005, 10:00 AM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default Dynamic addtion of DropDownLists at Runtime

Good morning all,

Quick, and hopefully easy question. I have a dynamic form where based on the information required there are a varying number of drop down lists needed. The number of dropdownlists is returned from a SQL DB.

For example, Customer A is interested in obtaining information for a shirt style, the drop down lists returned would be size, and color. Whereas for Customer B, would be returned Waist, Length, Color for Pant styles.

As stated, customer A would see 2 drop down lists, while customer B would see 3.

I hope this sufficiently explains it.

Regards,
Eric


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.dphin.com
 
Old October 17th, 2005, 11:39 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Ok, so what is your question?

 
Old October 18th, 2005, 06:55 AM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

I feel like I am brain dead and am just not looking at it the right way. My question is, how do I add the drop down lists to the webform after interrogating the SQL DB to retrieve the different lists. The Stored Procedure returns two tables, both of which are added to a dataset. One table contains the different drop down lists that are required, while the other table contains the list items.

For example: Dataset table 1 (the actual drop down lists)
1 Color Please select a color
2 Size Please select a size

Dataset Table 2 (the List Items for the options above)
1 Red 1
2 Blue 1
3 Green 1
4 Sm 2
5 Med 2
6 Lrg 2

The logic is escaping me, so any insight and possibly some VB code snippets would be very much appreciated.
 
Old October 18th, 2005, 06:59 AM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

One last point for clarification, these lists can not be hardcoded due to the fact that Color and Size are not the only lists available. For another product the option lists may be

Datalist Table 1:
Lens Color 1
Frame Type 2
Lens Type 3

Datalist Table 2:
The options which support the dropdownlists above.

Thanks again.
 
Old October 18th, 2005, 09:06 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Well, I would first determine what you need on the form. I guess a user will pick something, and a new page will display the lists. Based on some criteria:
1. Only get the data you will need into datasets
2. Add dropdowns to page dynamically, and add event handlers if necessary
3. Bind the drop downs.

 
Old October 18th, 2005, 09:16 AM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

Thank you for the reply.. I am aware of the workflow processes... I am just stumbling on the techinical, or How-To portion.

I am looking for insight as to how I would go about actually populating these "dynamic" dropdownlist's on the page. Would I use a Panel? How do you add webControls to a page when you dont know the name or how many there will be until run time based on selected criteria?
 
Old October 18th, 2005, 10:22 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Ok. I have just done a project recently with dynamically created controls. Be ready for some frustration doing this. It is much different than just dragging and droping and then coding. Here is some sample code I used to place dynamic controls (dropdowns) into a table on the form:

Dim ddlResponse As New DropDownList
ddlResponse.ID = "Name here"
'Manually added items
ddlResponse.Items.Add("")
ddlResponse.Items(0).Value = 1
ddlResponse.Items.Add("Good")
ddlResponse.Items(1).Value = 2
ddlResponse.Items.Add("Bad")
ddlResponse.Items(2).Value = 3
ddlResponse.Items.Add("Ugly")
ddlResponse.Items(3).Value = 4
'You can also use the dataset for the values:
ddlResponse.DataSource = <dataset>
ddlResponse.DataMember = <"table name">
ddlResponse.TextField = < dataset col>
ddlResponse.ValueField = <dataset col>
ddlResponse.DataBind()

ddlResponse.AutoPostBack = True 'Needed for event handler to work.
tdAnswers.Controls.Add(ddlResponse) ''Add to the table on the page.
'Add the event handler
AddHandler ddlResponse.SelectedIndexChanged, AddressOf ddl_SelectedIndexChanged

'This handler can be used by many controls.
Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  ... Do stuff here
End Sub

Make sure to add the controls to the FORM section of the page, otherwise you will get an error:

'Me.FindControl("Form1").Controls.Add(<control>)

Since you said you might use a panel, then it shoudln't be a problem. I added a table first then add my controls to it.

I hope this helps....

Jim

Any questions... let me know

 
Old October 18th, 2005, 12:48 PM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

Jim,

Thanks for the detailed explanation. To further the discussion, I see you hard coded the DropDownList declaration (Dim ddlResponse As New DropDownList), any idea how I would go about declaring a dropdownlist when I dont know the number of dropdownlists until runtime? I want to try and avoid hardcoding lets say 5 dropdownlists, when one product may use 2, while another will use all 5.

Many thanks.

Eric
 
Old October 18th, 2005, 02:14 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The hard coding was just an example. I also put in how you can bind the dropdown to a dataset.

 
Old October 18th, 2005, 03:20 PM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

I saw that... any idea how to declare the DropDownLists on the fly?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Dropdownlists in a repeater JadeCSharp ASP.NET 1.0 and 1.1 Basics 3 November 14th, 2007 06:34 PM
How to print from a dynamic gridview at runtime. VictorVictor ASP.NET 2.0 Professional 0 April 2nd, 2007 02:19 PM
Dropdownlists in DetailsView irelandk BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 February 20th, 2007 10:13 AM
Callback in 3 DropDownLists Paula222 ASP.NET 2.0 Professional 3 December 13th, 2006 08:53 AM
DropDownLists venterjo General .NET 1 January 8th, 2005 09:10 AM





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