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 July 26th, 2007, 07:10 AM
Authorized User
 
Join Date: May 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to swifty_programmer
Default selection with two or more linked dropdowns

Hi, I have a verry common scenario:

An ASP.NET 2.0 Web App (AJAX Enabled) where the user must select some criteria's to view the results in a gridview.

In this case it's a Company with multiple Vehicles possible. For each vehicle you can see some actions/registrations in a Gridview or DataList.

You have a DropDownList for selecting the company,
and another one for selecting the vehicles.

As the page Loads for the first time I want to load all possible companies in the first DropDownList. And because the first company in the list is selected I want to load all it's vehicles in the second DropDownList. until here: not difficult:

Code:
if (!IsPostBack && !IsCallback)
            {
                //Load All Companies
                _companies = Company.GetAllVersions();
                foreach (CompanyInfo company in _companies)
                {
                    _ddCompany.Items.Add(new ListItem(company.Name + " (" + company.Version.ToString() + ")", company.Id.ToString()));
                }

                if (_ddCompany.SelectedValue != null)
                {
                    _vehicles = Vehicle.GetByCompanyId(new Guid(_ddCompany.SelectedValue));
                    foreach (VehicleInfo vehicle in _vehicles)
                    {
                        _ddUnits.Items.Add(new ListItem(vehicle.Name + "-" + vehicle.UnitId, vehicle.UnitId.ToString()));
                    }
                }
The problem is when you change the company the list of Vehicle should load automaticly with the vehicles of that newly selected company, in preference not the rest of the page.
I tried the '_ddCompany_SelectedIndexChanged' but this event only get's fired after a postback. (Should I use updatepanel or PostBack Events with querrystrings, and with updatepanels: should I seperate the controls in different updatepanels or should I group some controls together in fewer updatepanels? wich one (2 dropdowns, some other selectioncriteriacontrols, and a list (eg DataList or Gridview)?)
It's too common problem for not already being solved. Can anyone point me the right direction?

Now I'm looking for the best way (most effective, fastest, most changeable) solution to do this but I didn't find anything usefull on Google and forums.

Thx guys
 
Old July 26th, 2007, 08:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

How about moving the code that binds the second drop down to its own method? E.g.:

private void BindVehicles()
{
  / Bind based on the value of ddCompany
}

Then in your own Page_Load and in SelectedIndexChanged simply call BindVehicles();

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 26th, 2007, 10:34 AM
Authorized User
 
Join Date: May 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to swifty_programmer
Default

Yes, I did that in the meanwhile to make it more easy for changes.
A simmple (and till now also good) solution:
I set the autopostback of first dropdrownlist on true and putted the two dropdownlists in the same updatepanel.
The job is done.
Now I'm struggling with QuerryStrings. I have additional popup-divs on that page to search the company or the Vehicle manually.
The results are displayed in a little DataList with a Hyperlink that reloads the page with correct querrystring.
Now my DropDownlist of Companies are stuck on the selected company (cannot change the selection).
I'm trying to find another way than with QuerryStrings but I'm not sure if it will make it easier or just the opposite. Will run few tests.

Imar, you've been such a good help, when done I will give you the url of what I'm building with a visitor login (it's an internal tool).
 
Old July 26th, 2007, 10:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome.

Would love to see what you're working on....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Dropdowns jasmine_vj Classic ASP Basics 2 April 17th, 2006 12:47 PM
Dropdowns in datagrid amithkiran ASP.NET 1.x and 2.0 Application Design 1 March 24th, 2005 05:33 AM
Three dropdowns, one depended on another. Possible gilgalbiblewheel Classic ASP Databases 2 December 26th, 2004 05:59 PM





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