- 爱易网页
-
C#教程
- 好几天了,小弟我快疯了?
日期:2014-05-18 浏览次数:20855 次
好几天了,我快疯了????????????????????
我的作法为:
1.我先作个首页,
<form id="form1" runat="server" >
<div >
<asp:Label ID="lanuage" runat="server" >Label </asp:Label >
<asp:DropDownList ID="drp_language" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_language_SelectedIndexChanged"
Width="152px" >
</asp:DropDownList >
<asp:Button ID="btnLogon" runat="server" Text="Button" OnClick="btnLogon_Click" / > </div >
</form >
后台:
public partial class index : System.Web.UI.Page
{
public static string strName;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
init();
}
}
private void init()
{
drp_language.DataSource = TangramMiniWeb.ResourceManager.GetSupportedLanguages();
drp_language.DataTextField = "name";
drp_language.DataValueField = "key";
drp_language.DataBind();
if (drp_language.Items.Count > 0)
{
strName = drp_language.SelectedValue;
ShowText(drp_language.Items[0].Value);
}
}
private void ShowText(string userlanguage)
{
btnLogon.Text = TangramMiniWeb.ResourceManager.GetString("GO", userlanguage);
//strName = btnLogon.Text = MultLanuage.ResourceManager.GetString("btnLogon", userlanguage);
lanuage.Text = TangramMiniWeb.ResourceManager.GetString("lanuage", userlanguage);
}
protected void drp_language_SelectedIndexChanged(object sender, EventArgs e)
{
ShowText(drp_language.SelectedValue);
strName = drp_language.SelectedValue;
}
protected void btnLogon_Click(object sender, EventArgs e)
{
Session["selectvalue"] = drp_language.SelectedValue.ToString();
Response.Redirect("tan/Default.aspx");
}
}
2.还写了个语言的基类:
public class ResourceManager
{
public ResourceManager()
{
//
}
public static string GetString(string name,string userLanguages)
{
//通过指定属性名返回包含此属性名相关信息的hash表
Hashtable source=LoadSorce(userLanguages);
if (source != null)
{
//不为空就返回其值
return source[name].ToString();
}
else
{
//为空
return "";
}