http://maddykalas.blogspot.in/
This post will explain you how to Bind Countries all over the world with their Currencies Symbols and Languages..
You always need to add the features like countries in your websites(feedback or registration form) so you need to hardcode it..
But .Net provide a class called CultureInfo through which we can easily bind all the countries list to the dropdownlist and so on..
Open a Webpage name it Culture_Info.aspx...
Culture_Info.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Culture_Info.aspx.cs" Inherits="Culture_Info" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td align="right">
All Language:
</td>
<td align="left">
<asp:DropDownList ID="ddlCulture" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">
All Countries:
</td>
<td align="left">
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlCountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">
Selected Country Language:
</td>
<td align="left">
<asp:DropDownList ID="ddlLang" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlLang_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">
Selected Country Currency Symbol:
</td>
<td align="left">
<asp:DropDownList ID="ddlCurrency" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">
Selected Language Native Name:
</td>
<td align="left">
<asp:DropDownList ID="ddlNative" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlLang_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Now
Culture_Info.aspx.cs
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Data;
using System.ComponentModel;
using System.Drawing;
using System.Collections;
public partial class Culture_Info : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetAllCountryLanguages();
GetAllRegions();
}
}
public void GetAllCountryLanguages()
{
ArrayList aL = new ArrayList();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
aL.Add(ci.DisplayName);
}
ddlCulture.DataSource = aL;
ddlCulture.DataBind();
}
public void GetAllLanguages(string Country)
{
ArrayList aL = new ArrayList();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if ((ci.EnglishName.ToString().Contains((Country)))) {
aL.Add(ci.EnglishName);
}
}
ddlLang.DataSource = aL;
ddlLang.DataBind();
GetAllNative(ddlLang.SelectedItem.Text);
GetAllCurrency(ddlLang.SelectedItem.Text);
}
public void GetAllCurrency(string Country)
{
RegionInfo info = new RegionInfo(new CultureInfo("en-US", false).Name);
ArrayList aL = new ArrayList();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if ((ci.EnglishName.ToString().Contains((Country))))
{
info = new RegionInfo(new CultureInfo(ci.Name, false).Name);
aL.Add(info.CurrencySymbol);
}
}
ddlCurrency.DataSource = aL;
ddlCurrency.DataBind();
}
public void GetAllRegions()
{
RegionInfo myRI2 = new RegionInfo(new CultureInfo("en-US", false).Name);
ArrayList aL = new ArrayList();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
myRI2 = new RegionInfo(new CultureInfo(ci.Name, false).Name);
aL.Add(myRI2.DisplayName);
}
ddlCountry.DataSource = aL;
ddlCountry.DataBind();
GetAllLanguages(ddlCountry.SelectedItem.Text);
GetAllCurrency(ddlCountry.SelectedItem.Text);
}
public void GetAllNative(string lang)
{
ArrayList aL = new ArrayList();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if ((ci.EnglishName.ToString().Contains((lang))))
{
aL.Add(ci.NativeName);
}
}
ddlNative.DataSource = aL;
ddlNative.DataBind();
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
GetAllLanguages(ddlCountry.SelectedItem.Text);
GetAllCurrency(ddlCountry.SelectedItem.Text);
}
protected void ddlLang_SelectedIndexChanged(object sender, EventArgs e)
{
GetAllCurrency(ddlLang.SelectedItem.Text);
GetAllNative(ddlLang.SelectedItem.Text);
}
}
Now just run the program..
You could see all the Countries name is being bind to DropDownList
Also the language with the currency symbols is binded to their respective DropDownList...
No comments:
Post a Comment