displaying chinese from code behind

  • Thread starter Thread starter Coco
  • Start date Start date
C

Coco

Hi!
I managed to display chinese character in my web form
(.aspx), in certain situation i need to to set the text of
the label of my web form in chinese character
programatically which is done in my code behind.

when running the web form, the character which is entered
directly to the web form during design time is displayed
correctly, while those set from code behind appear as
funny character

can anyone help?

i've changed my web config to the following
<globalization
requestEncoding="UTF-8"
responseEncoding="UTF-8"
fileEncoding="gb2312" />
 
Hi

I work with Shift_JIS and have never faced this problem
(though this used to happen in JSP for me and was really a
problem!!!)

I also tried simulating the problem, but watever i do,
aspx page gets rendered properly ;) tried saving the data
in different encodings in the VS.Net IDE. but doesnt give
any probs. Can u post/mail a sample code?


My Code is as follows
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="Dummy_ChineseTextAddToPageFromCB.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft
Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual
Basic 7.0">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
東京
<br>
とうきょう
<br>
トウキョウ
<br>
<asp:Label id="Label1" style="Z-
INDEX: 101; LEFT: 283px; POSITION: absolute; TOP: 80px"
runat="server">Label</asp:Label>
<br>
<br>
<br>
<br>
</form>
</body>
</HTML>


Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Response.Write("<br><br><br><br><br><br>文章田尻")
Label1.Text = "文章田尻"

End Sub


regards

sr
 
ok, this is my code behind


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Asialife.Life.Data;
using Asialife.Shared;
using Asialife.Shared.Data;
using Asialife.Shared.Entity;
using Asialife.Common.Charts;

namespace Asialife.NetTools
{
public class LILPFUND_CN : System.Web.UI.Page
{
protected Label UserLabel, MessageLabel, TitleLabel;
protected HtmlForm GridForm;
protected DataGrid ILPListing, ILPFundListing;
protected System.Web.UI.WebControls.Image ChartImage;
protected DropDownList PeriodList;
private ILPData ilpData;

private void Page_Load(object sender, System.EventArgs e)
{
initField();
if ((string)Session["dataViewID"]!="LILPFUND")
{
Session["dataViewID"] = "LILPFUND";
GetData();
}
else
{
bindGrid(1);
bindGrid(2);
}
}

private void GetData()
{
ilpData = new ILPData(PeriodList.SelectedItem.Value);
ilpData.Connect();
ilpData.Retrieve();
ilpData.Disconnect();
if (ilpData.IsExist)
{
Session["dataView"] = new DataView(ilpData.ReportTable);
Session["dataView1"] = new DataView(ilpData.ReportTable);
((DataView)Session["dataView"]).RowFilter="Date > '" +
DateTime.Today.AddDays(-8) + "' AND Date < '" + DateTime.Today + "'";
((DataView)Session["dataView"]).RowStateFilter=
DataViewRowState.CurrentRows;
((DataView)Session["dataView1"]).RowFilter="Fund = '" +
((DataView)Session["dataView1"])[0]["Fund"] + "'";
((DataView)Session["dataView1"]).Sort="Date";
((DataView)Session["dataView1"]).RowStateFilter=
DataViewRowState.CurrentRows;
TitleLabel.Text =
((DataView)Session["dataView1"])[0]["Fund"].ToString();
MessageLabel.Text="";
}
else
{
MessageLabel.Text="No Records Found !";
}
bindGrid(1);
bindGrid(2);
}

public void ILPGridPageChanged(object sender,
DataGridPageChangedEventArgs e)
{
ILPListing.CurrentPageIndex = e.NewPageIndex;
bindGrid(1);
}

public void ILPFundGridPageChanged(object sender,
DataGridPageChangedEventArgs e)
{
ILPFundListing.CurrentPageIndex = e.NewPageIndex;
bindGrid(2);
}

public void fundSelected(object sender, DataGridCommandEventArgs e)
{
TitleLabel.Text = e.Item.Cells[1].Text;
((DataView)Session["dataView1"]).RowFilter="Fund = '" +
e.Item.Cells[1].Text + "'";
((DataView)Session["dataView1"]).RowStateFilter=
DataViewRowState.CurrentRows;
bindGrid(2);
}

public void PeriodChanged(object sender, System.EventArgs e)
{
initGrid(1);
initGrid(2);
GetData();
}

private void initGrid(int gridNo)
{
switch(gridNo)
{
case 1:
ILPListing.CurrentPageIndex=0;
ILPListing.DataSource = new DataView();
ILPListing.DataBind();
break;
case 2:
ILPFundListing.CurrentPageIndex=0;
ILPFundListing.DataSource = new DataView();
ILPFundListing.DataBind();
break;
}
}

private void bindGrid(int gridNo)
{
switch(gridNo)
{
case 1:
ILPListing.DataSource = (DataView)Session["dataView"];
ILPListing.DataBind();
break;
case 2:
ILPFundListing.DataSource = (DataView)Session["dataView1"];
ILPFundListing.DataBind();
break;
}
}

private void initField()
{
if (!IsPostBack)
{
PeriodList.Items.Add(new ListItem("Áù¸öÔÂ",
DateTime.Today.AddMonths(-6).ToString("yyyyMMdd")) );
PeriodList.Items.Add(new ListItem("Ò»Äê",
DateTime.Today.AddYears(-1).ToString("yyyyMMdd")) );
PeriodList.Items.Add(new ListItem("Á½Äê",
DateTime.Today.AddYears(-2).ToString("yyyyMMdd")) );
PeriodList.Items.Add(new ListItem("ÎåÄê",
DateTime.Today.AddYears(-5).ToString("yyyyMMdd")) );
}
initGrid(1);
initGrid(2);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
 
I do not if i have to do some setting on my project or
vs.net
i tried to save the .cs file Chinese Simplified (GB2312) -
Codepage 936, but when i reopen the file without encoding
the funny character will appear again, so each time i want
to recompile my project i have to make sure all web form
that contain chinese character in the code behind is
opened with the encoding or else the chinese character
will appear as funny character
can anyone help me please?
-----Original Message-----
Hi

I work with Shift_JIS and have never faced this problem
(though this used to happen in JSP for me and was really
a
 
Back
Top