Introduction:
This article explains how to bind all countries to dropdownlist in asp.net using c#. By using System.Globalization namespace we can get all countries list in asp.net using c#.
Aspx Page:
C# Code:
OutPut:
This article explains how to bind all countries to dropdownlist in asp.net using c#. By using System.Globalization namespace we can get all countries list in asp.net using c#.
Aspx Page:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>binding all countries to dropdownlist in asp.net</title> </head> <body> <form id="form1" runat="server"> <div> <b>Select Country:</b><asp:DropDownList ID="ddlCountries" runat="server"/> </div> </form> </body> </html>
C# Code:
using System; using System.Web; using System.Globalization; using System.Collections.Generic; using System.Web.UI.WebControls; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<string> objcountries = new List<string>(); CultureInfo[] objculture = CultureInfo.GetCultures(CultureTypes.SpecificCultures); foreach (CultureInfo getculture in objculture) { RegionInfo objregion = new RegionInfo(getculture.LCID); if (!(objcountries.Contains(objregion.EnglishName))) { objcountries.Add(objregion.EnglishName); } } objcountries.Sort(); ddlCountries.DataSource = objcountries; ddlCountries.DataBind(); } }
OutPut:
No comments:
Post a Comment