1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections.Generic;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12using Microsoft.Win32;
13
14namespace DynamicWebSite.Framework
15{
16 public class CountryDropDownList : DropDownList
17 {
18 protected override void OnInit(EventArgs e)
19 {
20 base.OnInit(e);
21
22 //would need some kind of state persistence / one time loading here like if(!Page.IsPostBack) or what have you
23 this.DataSource = GetCountries();
24 this.DataBind ();
25
26 }
27
28
29 private List<string> GetCountries()
30 {
31 List<string> returnValues = new List<string>();
32
33 RegistryKey countries =
34 Registry.LocalMachine.OpenSubKey(
35 "Software\\Microsoft\\Windows\\CurrentVersion" +
36 "\\Telephony\\Country List");
37
38 if (countries != null)
39 {
40 // Get the list of subkeys,
41 // which is actually the country code
42 string[] subkeys = countries.GetSubKeyNames();
43
44 foreach (string ccode in subkeys)
45 {
46 // Open the subkey, to get the country name
47 RegistryKey country = countries.OpenSubKey(ccode);
48
49 // ..get the country name from country key
50 returnValues.Add(country.GetValue("Name").ToString());
51
52 // We're done using the key, we should close it
53 country.Close();
54 }
55
56 // It's now safe to close the country list key
57 countries.Close();
58 }
59
60 returnValues.Sort();
61 return returnValues;
62 }
63 }
64}