嘗試了裝.net2 Framework中文語言包、ReportView中文語言包、程序中採用中文屬性(AssemblyInfo.cs文件中設置[assembly: NeutralResourcesLanguageAttribute("zh-CN")])、安裝windows最新補丁等方法,都沒有辦法實現。最後在msdn看到了Microsoft.Reporting.WebForms中一個接口IReportViewerMessages的介紹:使應用程序可以提供自定義的用戶界面消息。因此嘗試用實現此接口的方法來實現。
在App_Code目錄下新建ReportViewerMessagesZhcn.cs類,讓他實現IReportViewerMessages接口,代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Reporting.WebForms;
namespace AdminConsole.App_Code
{
public class ReportViewerMessagesZhcn : IReportViewerMessages
{
#region IReportViewerMessages Members
public string BackButtonToolTip
{
get { return ("後退"); }
}
public string ChangeCredentialsText
{
get { return ("更改"); }
}
public string ChangeCredentialsToolTip
{
get { return ("ChangeCredentialsToolTip."); }
}
public string CurrentPageTextBoxToolTip
{
get { return ("當前頁"); }
}
public string DocumentMap
{
get { return ("文檔視圖"); }
}
public string DocumentMapButtonToolTip
{
get { return ("文檔視圖."); }
}
public string ExportButtonText
{
get { return ("導出"); }
}
public string ExportButtonToolTip
{
get { return ("導出"); }
}
public string ExportFormatsToolTip
{
get { return ("選擇格式."); }
}
public string FalseValueText
{
get { return ("不正確的值."); }
}
public string FindButtonText
{
get { return ("查找"); }
}
public string FindButtonToolTip
{
get { return ("查找"); }
}
public string FindNextButtonText
{
get { return ("下一個"); }
}
public string FindNextButtonToolTip
{
get { return ("查找下一個"); }
}
public string FirstPageButtonToolTip
{
get { return ("第一頁"); }
}
public string InvalidPageNumber
{
get { return ("頁面數不對"); }
}
public string LastPageButtonToolTip
{
get { return ("最後一頁"); }
}
public string NextPageButtonToolTip
{
get { return ("下一頁"); }
}
public string NoMoreMatches
{
get { return ("無匹配項"); }
}
public string NullCheckBoxText
{
get { return ("空值"); }
}
public string NullValueText
{
get { return ("空值"); }
}
public string PageOf
{
get { return ("頁"); }
}
public string ParameterAreaButtonToolTip
{
get { return ("參數設置"); }
}
public string PasswordPrompt
{
get { return ("PasswordPrompt"); }
}
public string PreviousPageButtonToolTip
{
get { return ("上一頁"); }
}
public string PrintButtonToolTip
{
get { return ("打印"); }
}
public string ProgressText
{
get { return ("正在生成報表......"); }
}
public string RefreshButtonToolTip
{
get { return ("刷新"); }
}
public string SearchTextBoxToolTip
{
get { return ("查找"); }
}
public string SelectAValue
{
get { return ("SelectAValue"); }
}
public string SelectAll
{
get { return ("全選"); }
}
public string SelectFormat
{
get { return ("選擇格式"); }
}
public string TextNotFound
{
get { return ("未找到"); }
}
public string TodayIs
{
get { return ("TodayIs"); }
}
public string TrueValueText
{
get { return ("TrueValueText"); }
}
public string UserNamePrompt
{
get { return ("UserNamePrompt"); }
}
public string ViewReportButtonText
{
get { return ("查看報表"); }
}
public string ZoomControlToolTip
{
get { return ("縮放"); }
}
public string ZoomToPageWidth
{
get { return ("頁寬"); }
}
public string ZoomToWholePage
{
get { return ("整頁"); }
}
#endregion
}
}
最後在web.config中設置該類對ReportViewer的控制:
在 <appSettings> 節中添加 ReportViewerMessages 屬性,代碼如下:
<appSettings>
<add key="ReportViewerMessages" value="AdminConsole.App_Code.ReportViewerMessagesZhcn,App_Code" />
</appSettings>
編譯發佈,最後測試結果爲工具欄顯示爲中文,問題得到解決。
遺留問題:導出的格式下拉框還是英文,打印對話框也是英文。
歡迎各位來交流,尋求遺留問題的解決方案。
以下爲最終解決方案:
...................
<globalization fileEncoding= "utf-8" culture="zh-cn" uiCulture= "zh-cn"/>
</system.web>