Archive

Archive for July, 2017

Get and Bind all Countries to DropdownList Using Globalization

July 17, 2017 Leave a comment

Hi all,

Try this example to Get and Bind all Countries to Dropdownlist Using Globalization

Select Country:

<asp:DropDownList ID="ddlcountry" runat="server"> </asp:DropDownList>

In Code behind :


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetAllCountry();
}
}

public void GetAllCountry()
{
try
{
List<string> listcountry = new List<string>();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo cinfo in cultures)
{
RegionInfo Rinfo = new RegionInfo(cinfo.LCID);
if (!listcountry.Contains(Rinfo.EnglishName))
{
listcountry.Add(Rinfo.EnglishName);
}
}
listcountry.Sort();
ddlcountry.DataSource = listcountry;
ddlcountry.DataBind();
ddlcountry.Items.Insert(0, new ListItem("--Select Country--", "0"));
}
catch (Exception ex)
{
}
}

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net