Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

Load all the Country Names of the World in DropDown

5.00/5 (2 votes)
7 May 2011CPOL 19.2K  
Step1.Downlo...
Step1.
Download coma separated .CSV country file.
Step2.
Create new table for country
suppose CountryId,Country are their fields.

SQL
USE TestData
GO
CREATE TABLE Tbl_COUNTRY
( 
CountryId VARCHAR(40),
Country VARCHAR(40)
)
GO

Step3.
Now run following script to load all the data from CSV to database table
SQL
BULK
INSERT Tbl_COUNTRY
FROM 'c:\country_data.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO


Step4.
C#
protected void Page_Load(object sender, EventArgs e)
 {
        
        ddlLocation.DataSource = LoadCountryData() as DataTable;
        ddlLocation.DataTextField = "Country";
        ddlLocation.DataValueField = "CountryId";
        ddlLocation.DataBind();
 }


Download countrylist.csv
countrylist.txt[^]
coutrylist.csv[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)