using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Globalization; using System.Threading; public partial class NewsShow : System.Web.UI.Page { public string id; public DataTable dtnews; protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["Tid"] != null) { id = Request.QueryString["Tid"].ToString(); dtnews = newsShow(id); } } public DataTable newsShow(string id) { if (string.IsNullOrEmpty(id)) { Response.Redirect("newslist.aspx"); return null; } else { string sql; if (Session["Lang"] != null) { if (Session["Lang"].ToString() == "zh-cn") { sql = "select title_cn,body_cn,editdate,source,imgs from newstab where id='" + id + "' "; } else { sql = "select title_en as title_cn,body_en as body_cn,editdate,source,imgs from newstab where id='" + id + "' "; } } else { sql = "select title_cn,body_cn,editdate,source,imgs from newstab where id='" + id + "' "; } DataTable dt = DBH.DBHelper.GetDataSet(sql); return dt; } } protected void LinkButton1_Click(object sender, EventArgs e) { Session["Lang"] = "zh-cn"; Response.Redirect(Request.Url.ToString()); } protected void LinkButton2_Click(object sender, EventArgs e) { Session["Lang"] = "en-us"; Response.Redirect(Request.Url.ToString()); } protected override void InitializeCulture() { if (Session["lang"] != null) { string lang = Session["lang"].ToString(); if (!String.IsNullOrEmpty(lang)) { //UICulture - 决定了采用哪一种本地化资源,也就是使用哪种语言 //Culture - 决定各种数据类型是如何组织,如数字与日期 Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang); base.InitializeCulture(); } } } }