ASP.Net/Page/Culture — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:53, 26 мая 2010

Culture auto (C#)

   <source lang="csharp">

<%@ Page Language="C#" Culture="auto:en-US" UICulture="auto:en-US"%> <script runat="server">

   void Page_PreRender()
   {
       lblDate.Text = DateTime.Now.ToString("D");
       lblPrice.Text = (512.33m).ToString("c");
   }

</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>Select Culture Auto</title>

</head> <body>

   <form id="form1" runat="server">
   Today"s date is:
   
<asp:Label id="lblDate" Runat="server" />

The price of the product is:
<asp:Label id="lblPrice" Runat="server" />
   </form>

</body> </html>

      </source>
   
  


Culture: id-ID

   <source lang="csharp">

<%@ Page Language="C#" Culture="id-ID" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>Show Calendar</title>

</head> <body>

   <form id="form1" runat="server">
   <asp:Calendar
       id="Calendar1"
       Runat="server" />
   
   </form>

</body> </html>

      </source>
   
  


Get Culture: de_DE, id-ID (C#)

   <source lang="csharp">

<%@ Page Language="C#" %> <%@ Import Namespace="System.Globalization" %> <script runat="server">

   void Page_Load()
   {
       // Get German Culture Info
       CultureInfo gCulture = new CultureInfo("de-DE");
       
       // Use culture when formatting strings
       lblGermanDate.Text = DateTime.Now.ToString("D", gCulture);
       lblGermanPrice.Text = (512.33m).ToString("c", gCulture);
       // Get Indonesian Culture Info
       CultureInfo iCulture = new CultureInfo("id-ID");
       // Use culture when formatting strings
       lblIndonesianDate.Text = DateTime.Now.ToString("D", iCulture);
       lblIndonesianPrice.Text = (512.33m).ToString("c", iCulture);
   }

</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>ToString Culture</title>

</head> <body>

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

German

   Today"s date is:
   
<asp:Label id="lblGermanDate" Runat="server" />

The price of the product is:
<asp:Label id="lblGermanPrice" Runat="server" />

Indonesian

   Today"s date is:
   
<asp:Label id="lblIndonesianDate" Runat="server" />

The price of the product is:
<asp:Label id="lblIndonesianPrice" Runat="server" />
   </form>

</body> </html>

      </source>
   
  


Get culture from binded ObjectDataSource (C#)

   <source lang="csharp">

<%@ Page Language="C#" %> <script runat="server">

   protected void btnSelect_Click(object sender, EventArgs e)
   {
       Culture = ddlCulture.SelectedValue;
   }
   void Page_PreRender()
   {
       lblDate.Text = DateTime.Now.ToString("D");
       lblPrice.Text = (512.33m).ToString("c");
   }

</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>Select Culture</title>

</head> <body>

   <form id="form1" runat="server">
   <asp:Label
       id="lblCulture"
       Text="Culture:"
       AssociatedControlID="ddlCulture"
       Runat="server" />
       
   <asp:DropDownList
       id="ddlCulture"
       DataTextField="DisplayName"
       DataValueField="Name"
       DataSourceID="srcCultures"
       Runat="server" />    
   <asp:Button
       id="btnSelect"
       Text="Select"
       Runat="server" OnClick="btnSelect_Click" />
       
       
   <asp:ObjectDataSource
       id="srcCultures"
       TypeName="System.Globalization.CultureInfo"
       SelectMethod="GetCultures"
       Runat="server">
       <SelectParameters>
           <asp:Parameter Name="types" DefaultValue="SpecificCultures" />
       </SelectParameters>
   </asp:ObjectDataSource>        

   Today"s date is:
   
<asp:Label id="lblDate" Runat="server" />

The price of the product is:
<asp:Label id="lblPrice" Runat="server" />
   </form>

</body> </html>

      </source>
   
  


Page Culture (C#)

   <source lang="csharp">

<%@ Page Language="C#" Culture="id-ID" UICulture="id-ID" %> <script runat="server">

   void Page_Load()
   {
       lblDate.Text = DateTime.Now.ToString("D");
       lblPrice.Text = (512.33m).ToString("c");
   }

</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>Bagus</title>

</head> <body>

   <form id="form1" runat="server">
   Today"s date is:
   
<asp:Label id="lblDate" Runat="server" />

   The price of the product is:
   
<asp:Label id="lblPrice" Runat="server" />
   </form>

</body> </html>

      </source>
   
  


Set culture in the web.config

   <source lang="csharp">

<?xml version="1.0"?> <configuration xmlns="http://schemas.microsoft.ru/.NetConfiguration/v2.0">

 <system.web>
   <anonymousIdentification enabled="true"/>
   <profile>
     <properties>
       <add 
         name="UserCulture"
         defaultValue="en-US" />
       <add 
         name="UserUICulture"
         defaultValue="en" />
     </properties>
   </profile>
 </system.web>

</configuration>

      </source>