473,412 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

ASP.NET 1.1: Country DropDownList

Hello People!

Recently i had the need to make a country dropdownlist, ive been searching all over the net, for a way to populate the dropdown from the culture or somewhere.

The thing is all examples i find, either read from a text file, or from an xml file, or from the database.

I just cant believe .net doesnt have something like that, i just think there must be an easier way to populate a country dropdown from a source provided by .net, java has a similar thing:

Expand|Select|Wrap|Line Numbers
  1. Locale[] l = Locale.getLocales();
then you just call

Expand|Select|Wrap|Line Numbers
  1. getDisplayName()
and voila!

anyway....anyone here know how to do this in .net1.1?
Jan 28 '08 #1
9 2152
Plater
7,872 Expert 4TB
The names of countries change almost daily. It would be rather difficult to have an object built in to .NET to track that.

Just make a datatable full of the most common ones. (Try "borrowing" it from another website) and set it as a datasource?
Jan 28 '08 #2
r035198x
13,262 8TB
Hello People!

Recently i had the need to make a country dropdownlist, ive been searching all over the net, for a way to populate the dropdown from the culture or somewhere.

The thing is all examples i find, either read from a text file, or from an xml file, or from the database.

I just cant believe .net doesnt have something like that, i just think there must be an easier way to populate a country dropdown from a source provided by .net, java has a similar thing:

Expand|Select|Wrap|Line Numbers
  1. Locale[] l = Locale.getLocales();
then you just call

Expand|Select|Wrap|Line Numbers
  1. getDisplayName()
and voila!

anyway....anyone here know how to do this in .net1.1?
Perhaps something like


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Globalization;
  3. namespace Cultures
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             foreach(CultureInfo info in CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures)) {
  10.                 string culture = info.EnglishName;
  11.                 string[] data = culture.Split(new char[]{'('});
  12.                 string country = data[data.Length - 1];
  13.                 country = country.Replace(")", "");
  14.                 Console.WriteLine(country);
  15.             }
  16.             Console.ReadLine();
  17.         }
  18.     }
  19.  
  20.  
  21.     }
  22.  
Jan 28 '08 #3
Plater
7,872 Expert 4TB
Well, color me wrong once again.
Jan 28 '08 #4
r035198x
13,262 8TB
Well, color me wrong once again.
A lot of fiddling around if you ask me. Nothing to be proud of.
I hope there's a cleaner way of doing it.
Jan 28 '08 #5
A lot of fiddling around if you ask me. Nothing to be proud of.
I hope there's a cleaner way of doing it.
well, might not be clean(who cares?), but it works, thanks!
Jan 28 '08 #6
r035198x
13,262 8TB
well, might not be clean(who cares?), but it works, thanks!
Erm, I hope you noticed that the method gives some duplicate countries because some countries have multiple cultures. You'd need to add those in a set to remove the duplicates.
Jan 28 '08 #7
You could consume a public web service that provides the county codes and country name. You will just have to trust or validate what countries they provide in the soap (xml) response.
Jan 28 '08 #8
Erm, I hope you noticed that the method gives some duplicate countries because some countries have multiple cultures. You'd need to add those in a set to remove the duplicates.
yes i noticed, i just did the following:

Expand|Select|Wrap|Line Numbers
  1. string culture = info.EnglishName;
  2.                 string[] data = culture.Split(new char[]{'('});
  3.                 string country = data[data.Length - 1];
  4.                 country = country.Replace(")", "");
  5.  
  6.                 if( c.Items.FindByValue(country) == null )
  7.                     c.Items.Add(new ListItem(country, country));
Jan 28 '08 #9
You could consume a public web service that provides the county codes and country name. You will just have to trust or validate what countries they provide in the soap (xml) response.
well, im just populating a drop down list, making a webservice for such i think is just too much.

but your suggestion comes in handy for more complicated issues, thanks.
Jan 28 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
1
by: aish | last post by:
I have asp.net C# web app. it has country dropdownlist.when the page load I want to select current users country. how can I do this? I want to use client side code for this, can I do this using...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
7
by: Lloyd Dupont | last post by:
from the IP of the request ?
1
by: S.Guhananth | last post by:
I need to capture a country from dropdown list and use that in sql query. How to do this protected DataSet GetCountry() { I have the code for this block
2
by: gomzi | last post by:
hi, Suppose i want the user to specify his country at the time of registration, then should i provide a textbox or go for a dropdownlist(one cant be sure of covering all the countries...)? ...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
11
by: pinocchio123 | last post by:
hi friends... in my php page 3 dropdownlist boxes are there.. ie country,state,city.. if country is selected, in onchange function.. corresponding states has to be populated in state...
1
by: rajanji | last post by:
Hi All, I am creating a job portal in asp.net2.0 and mysql as backend.... I want to create a drop down list.... which displays the list of states according to the country selected in the first...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.