hi
i want to populate country's name in 1st dropdownlist and their states should be placed in the 2nd dropdownlist, if we select any state it should place the name of the capital in the textbox besides that and so on.....
If possible send me code
thank you in advance
raghu
you should keep a good table structure for your work....I recommend four(4) tables to create...
1.tblCountry_Master
------------------------------
CountryId(PrimaryKey),CountryName
2.tblSate_Master
-----------------------
StateID(PK),StateName
3. tblStateCountryRelation
-------------------------------------
CountryId,StateId
4.tblStateCapital
-------------------------------
StateId(PK),Capital_Name
populate your country dropdown first with sql like...........
- SELECT * FROM tblCountry_Master
make a dataset.....set the
datasource of the dropdown to the
Dataset.
if you are making a windows application then set
ValueMember of the dropdownlist to "CountryId" and
DisplayMember to
"CountryName"[ you have not mentioned about your application.......In web application these are
DataValueField and
DataTextField...........]
Now in the
SelectedIndexChanged event of your country dropdown choose the valuefield(Here it is
CountryId)
-
- Dim country_id As String
- country_id = myDropdown.SelectedValue
-
Now after getting the country_id you can easily fetch the corresponding statename with a simple query like....
-
- SELECT StateID,StateName FROM tblSate_Master S INNER JOIN
- tblStateCountryRelation SC ON S.StateID=SC.StateId WHERE
- CountryId='" & country_id & "'
again create a dataset with these records and bind it to State dropdownlist
Repeat the above mechanism for state capital name:: --------------------------------------------------------------------------------
In the
SelectedIndexChanged event of your state dropdown choose the valuefield(Here it is
StateId)..........and choose the capital from
tblStateCapital with sql statement
- SELECT Capital_Name FROM tblStateCapital WHERE
- StateId='" & state_id & "'
-
Hope you understand.........I have not given you the full code ......try yourself....I think you can do it now........