我有一個帶有日曆的網頁,一個用於存放貨幣價值的標籤以及一個打招呼的標籤。當我從下拉列表中選擇一種語言時,它會更改貨幣標籤,日曆,但是您不會更改。下面是aspx頁面和CS文件的精簡代碼:貨幣,日曆更改爲選定的語言,但在asp.net中沒有標籤?
ASPX:
<asp:Label ID="lblLanguageSelection" runat="server"
Text="Select a language: "></asp:Label>
<asp:DropDownList ID="ddlLanguages" runat="server" AutoPostBack="true">
<asp:ListItem Value="auto">Auto</asp:ListItem>
<asp:ListItem Value="en-US">English (US)</asp:ListItem>
<asp:ListItem Value="en-GB">English (GB)</asp:ListItem>
<asp:ListItem Value="de">German</asp:ListItem>
<asp:ListItem Value="fr">French</asp:ListItem>
<asp:ListItem Value="fr-CA">French (Canada)</asp:ListItem>
<asp:ListItem Value="hi">Hindi</asp:ListItem>
<asp:ListItem Value="th">Thai</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br /><br />
<asp:Label ID="lblCurrency" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="lblHello" runat="server"></asp:Label>
CS:
protected void Page_Load(object sender, EventArgs e)
{
decimal currency = 65542.43M;
string hello = "Hello";
lblCurrency.Text = string.Format("{0:c}", currency);
lblHello.Text = string.Format("{0}",hello);
}
protected override void InitializeCulture()
{
string language = Request["ddlLanguages"];
if (language != null)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(language);
}
}
謝謝,我從我觀看的視頻中抽取了樣本。我從來沒有真正使用過請求。我相信這個人說他們使用了Request,因爲這個值可能不會在運行時初始化,而SelectetdValue會拋出一個錯誤。 – Xaisoft 2009-03-03 21:48:37