Wednesday, September 28, 2011

How to used Cultures of different language in ASP.net

Posted by Rahul Kharde at 3:36 AM
We want develop a system in different languages. Naturally, all the content of these sites will be in the respective language. The content includes static text, form labels, prompts, error messages and similar things. In addition you would also like to take care of things such as date formats and number formats. Typically you will choose one of the following approaches to develop such web sites

The culture can be set for a thread using Thread.CurrentThread.CurrentCulture property.

using System.Threading.CurrentThread

The culture can be set for a thread using Thread.CurrentThread.CurrentCulture property.

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

HTML

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<%=DateTime.Now.ToLongDateString() %>

<br />

<%=dt.ToLongDateString() %>

<br />

<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"

BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"

Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="112px"

ShowGridLines="True" Width="125px">

<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />

<SelectorStyle BackColor="#FFCC66" />

<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />

<OtherMonthDayStyle ForeColor="#CC9966" />

<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />

<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />

<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"

ForeColor="#FFFFCC" />

</asp:Calendar>

<br />

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"

onselectedindexchanged="DropDownList1_SelectedIndexChanged">

<asp:ListItem Value="en-US" Selected="True">English</asp:ListItem>

<asp:ListItem Value="es-MX">EspaƱol</asp:ListItem>

<asp:ListItem Value="de-DE">Deutsch</asp:ListItem>

<asp:ListItem Value="mr-IN">Marathi</asp:ListItem>

<asp:ListItem Value="hi-IN">Hindi (India)</asp:ListItem>

<asp:ListItem Value="gu-IN">Gujarati (India)</asp:ListItem>

<asp:ListItem Value="ja-JP">Japanese </asp:ListItem>

</asp:DropDownList>

</div>

</form>

</body>

</html>

Code

public static DateTime dt = new DateTime();

protected void Page_Load(object sender, EventArgs e)

{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

dt = (DateTime)Calendar1.SelectedDate;

System.Threading; Thread.CurrentThread.CurrentCulture = new CultureInfo(DropDownList1.SelectedItem.Value.ToString());

}

For English (en-US) Culture setting

For Marathi-India (mr-IN) Culture setting

Download

Download Code Here…



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

1 comments:

Abhijit Shrivas on August 16, 2012 at 3:43 AM said...

thx a lot it working fine


Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top