Aim
We want to Select the Name of the Country from the Dropdownlist and On Selecting a Particular Country, A list of State is populated in the second Dropdownlist control from SQL Database.
Step 1: Creating the Database Structure.
- Create Database DDLDemo
- Use DDLDemo
- Create Table Country(ID int Identity Primary Key, Name nvarchar(50))
- Create Table [State](ID int Identity Primary Key, Name nvarchar(50), CountryID int FOREIGN KEY References Country(ID))
- Insert Into Country Values ('India')
- Insert Into Country Values ('USA')
- Insert Into Country Values ('China')
- Insert Into Country Values ('Australia')
- Insert Into Country Values ('United Kingdom')
- Select * from Country
- Select * from State
- Insert Into State Values ('Delhi',1)
- Insert Into State Values ('UP',1)
- Insert Into State Values ('Kanpur',1)
- Insert Into State Values ('Lucknow',1)
- Insert Into State Values ('New York',2)
- Insert Into State Values ('Boston',2)
- Insert Into State Values ('Chile',2)
- Insert Into State Values ('Japan',3)
- Insert Into State Values ('Tokyo',3)
- Insert Into State Values ('Shinghai',3)
- Insert Into State Values ('Vietnam',3)
- Insert Into State Values ('Delhi',4)
- Insert Into State Values ('Sydney',4)
- Insert Into State Values ('Malbourne',4)
- Insert Into State Values ('England',5)
- Insert Into State Values ('London',5)
- Insert Into State Values ('Singapore',5)
- --This is a query using Inner join which shows all the city for their respective countries.
- Select c.Name as Country, s.Name as State from Country c INNER JOIN State s ON c.ID = s.CountryID

Join the conversation! Your thoughts help the community grow.