Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Billkamm
Posting Yak Master
124 Posts |
Posted - 2006-01-12 : 08:51:58
|
Hi, I'm looking for the best way to update a dropdownlist's list based on a value choosen from another dropdownlist on the page.A common example of this is there are two DDLs. One for state and one for county. The county DDL is left blank until a state is choosen. Once a state is choosen then the county dropdownlist is filled.Now here is part of my dilemma. I'm entered other data on the form, so if I postback I need some way of knowing that the postback is just for the purpose of filling the secont dropdownlist. In addition everytime that first DDL is changed it should update the second dropdownlist accordingly.Another problem I have is that the DDLs are at the bottom of a long page and I want the page to return to the same view the user had before (instead of at the top of the page after the postback).I had considered dynamically writing JavaScript code to fill these DDLs, but I'm sure this is not the best way of approached the problem. Can anyone offer any suggestions? |
|
jhermiz
3564 Posts |
Posted - 2006-01-12 : 16:36:09
|
quote: Originally posted by Billkamm Hi, I'm looking for the best way to update a dropdownlist's list based on a value choosen from another dropdownlist on the page.A common example of this is there are two DDLs. One for state and one for county. The county DDL is left blank until a state is choosen. Once a state is choosen then the county dropdownlist is filled.Now here is part of my dilemma. I'm entered other data on the form, so if I postback I need some way of knowing that the postback is just for the purpose of filling the secont dropdownlist. In addition everytime that first DDL is changed it should update the second dropdownlist accordingly.Another problem I have is that the DDLs are at the bottom of a long page and I want the page to return to the same view the user had before (instead of at the top of the page after the postback).I had considered dynamically writing JavaScript code to fill these DDLs, but I'm sure this is not the best way of approached the problem. Can anyone offer any suggestions?
I suggest an asp.net book, I am not trying to be rude but these are basic questions that you should be able to find and learn from yourself:For the first issue you simply have to pass the PK or identifier that relates to the second combo box (your example to me doesnt make sense, why would states be first and country second?) A typical example is cars with models. First ddl is the car make (GM, FORD, DCX) the second ddl is the model (MUSTANG, ESCAPE, MAGNUM, etc). So when someone selects FORD in the first drop down you take that identifier (prolly the PK from your table) and pass it to a sproc that pulls the model just for ford and fills it. SELECT Model FROM CarModel WHERE CarMake=@CarMake@CarMake simply has the car make: GM, Chrysler or Ford etc...Also make sure you clear the combo box and repopulate if someone changes their mind or makes a mistake.Few other things, Look into IsPostBack, this determines whether the page should be posting back or not...also the DDL has a property to PostBack after a value has changed (right in the properties dialog).As for moving to the right part of the page, I think the site 4guysfromrolla can help:http://www.4guysfromrolla.comGood luck,Jon Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url] |
 |
|
|
|
|
|
|