yagu99
asked on
Dynamically fill a drop down list from data in a database in Visual Studio
I'm trying to dynamically fill 3 drop down lists from data in my database using Visual Studio.
DDL 1 = States
DDL 2 = Cities
DDL 3 = Zip Codes
DDL 1 should get its data from the database. Then depending on what state is selected in DDL 1, DDL 2 should populate with the Cities for that State. Then DDL 3 should populate with the zip codes available for that city. All drop down lists should get the data from two database tables.
(E.g. DDL 1 I select FL as the State, then DDL 2 populates with Orlando, Jacksonville, Miami, I select Orlando as the City. Then, DDL 3 populates with the zip codes for Orlando.)
How is this accomplished in visual studio?
Thanks for the help
DDL 1 = States
DDL 2 = Cities
DDL 3 = Zip Codes
DDL 1 should get its data from the database. Then depending on what state is selected in DDL 1, DDL 2 should populate with the Cities for that State. Then DDL 3 should populate with the zip codes available for that city. All drop down lists should get the data from two database tables.
(E.g. DDL 1 I select FL as the State, then DDL 2 populates with Orlando, Jacksonville, Miami, I select Orlando as the City. Then, DDL 3 populates with the zip codes for Orlando.)
How is this accomplished in visual studio?
Thanks for the help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As you were asked by emoreau, is this a Web App or Windows App?
If it's a Web App then I can post exactly how I've done it... (Using a Web Service and DataSets, using SQL 2005)
If it's a Web App then I can post exactly how I've done it... (Using a Web Service and DataSets, using SQL 2005)
ASKER
It is a web app
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here are the two tables with their attributes
Categories Table
CategoryID int identity PK
CategoryName nvarchar(100)
Description nvarchar(100)
ParentCategoryID int FK to dbo.Categories.CategoryID Allows Nulls
ParentCodeID int FK to dbo.Codes.CodesID Allows Nulls
Codes Table
CodesID int Identity PK
CategoryID int FK to dbo.Categories.CategoryID
CodeName nvarchar(100)
Description nvarchar(100)
I have the folllowing data in the Categories table:
CategoryID = 1
CategoryName = States
Description = US States
ParentCategoryID = NULL
ParentCodeID = NULL
CategoryID = 2
CategoryName = Cities
Description = US Cities
ParentCategoryID = 1
ParentCodeID = NULL
CategoryID = 3
CategoryName = Zip Codes
Description = US Zips
ParentCategoryID = 2
ParentCodeID = NULL
I have the following information in the Codes Table:
CodeID = 1
CategoryID = 1
CodeName = Florida
Description = State of Florida
CodeID = 2
CategoryID = 1
CodeName = Georgia
Description = State of Georgia
CodeID = 3
CategoryID = 2
CodeName = Orlando
Description = City of Florida
CodeID = 4
CategoryID = 2
CodeName = Miami
Description = City of Florida
CodeID = 5
CategoryID = 2
CodeName = Atlanta
Description = City of Georgia
CodeID = 6
CategoryID = 2
CodeName = Cleveland
Description = Cityof Georiga
CodeID = 7
CategoryID = 3
CodeName = 11111
Description = Zip of Orlando
CodeID = 8
CategoryID = 3
CodeName = 11112
Description = Zip of Orlando
CodeID = 9
CategoryID = 3
CodeName = 21111
Description = Zip of Miami
CodeID = 10
CategoryID = 3
CodeName = 21112
Description = Zip of Miami
CodeID = 11
CategoryID = 3
CodeName = 31111
Description = Zip of Atlanta
CodeID = 12
CategoryID = 3
CodeName = 32211
Description = Zip of Atlanta
CodeID = 13
CategoryID = 3
CodeName = 41111
Description = Zip of Cleveland
CodeID = 14
CategoryID = 3
CodeName = 41112
Description = Zip of Cleveland
So based on this idea:
The 1st DDL should be the States
The 2nd DDL should be the cities based on the State Selected
The 3rd DDL should be the zips for the City Selected
The DDL's must read the database & not be statically entered into the VB web form.
I also have two stored procedures where it selects all of the categories & the other selects all of the Codes. Not really for sure what to do with the ParentCodeID field in the dbo.Categories Table.