|
-
Mar 9th, 2004, 04:33 AM
#1
Thread Starter
Addicted Member
binding all countries to a combobox?!
hi, i have a registeration form , one of the fields in nationality so i need a list of all countries in alphabetical order , this is what i could think of
Code:
Dim cultures() As System.Globalization.CultureInfo = System.Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.SpecificCultures)
Dim countries As New System.Collections.ArrayList()
Dim enm As IEnumerator = cultures.GetEnumerator
While enm.MoveNext
Dim str As String = CType(enm.Current, System.Globalization.CultureInfo).EnglishName
Dim start As Int16 = str.IndexOf("(") + 1
Dim finish As Int16 = str.IndexOf(")")
countries.Add(str.Substring(start, finish - start))
End While
countries.Sort()
nationality.DataSource = countries
there must be an easier way
-
Mar 9th, 2004, 11:19 AM
#2
Sleep mode
-
Mar 9th, 2004, 12:07 PM
#3
PowerPoster
Try using the SortListed Collection. Here is a quick snippet (it's in C#, but im sure you can decipher):
Code:
private void Page_Load(object sender, System.EventArgs e) {
if (!Page.IsPostBack) {
CultureInfo[] c = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
SortedList countries = new SortedList();
foreach (CultureInfo o in c) {
countries.Add(o.Name, o.EnglishName);
}
ddlCountries.DataTextField = "Value";
ddlCountries.DataSource = countries;
ddlCountries.DataBind();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|