Monday, August 07, 2006

How to localize the ReportViewer control in ASP.NET 2.0

The ReportViewer control in ASP.NET 2.0 allows you to display SQL server reporting services style reports. The reports can come from a SQL server reporting service (server mode), or from the website itself (local mode).

If you run the ReportViewer in local mode, you can also bind it to your business logic directly, instead of having to bind it to a database directly.

I found localizing the reports a bit tricky and not well documented, so here is a step by step guide:

  • When I installed Visual Studio 2005, only the English version of the report viewer itself was installed. The toolbar buttons for searching, exporting, etc. were displayed only in English. First you have to download and install the Microsoft Report Viewer Redistributable 2005. You will need to install this even if you have Visual Studio 2005 installed, as otherwise the installation of the following download will crash (at least it did that on my machine).

  • Now you can download the Microsoft Report Viewer 2005 Language Pack. Go here, choose the language from the dropdown, download and install for each language that you want to support.

  • If you run the report viewer now, you can see the localized toolbar.

  • In order for the report itself to display localized formats for currencies, dates, etc., make sure you have set the Language property of your report either to default, or to the desired language. This property is initialized to English if you use the English version of Visual Studio.

  • You also have to make sure that the thread is using the correct culture settings. This will default to the setting of your server. You can override it with the language the user has selected in his browser by doing something like

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

    in a suitable place, like the page load or session start.

  • Finally, make sure you use culture aware formatting settings in your report, for example "C" for currencies.


Shahid said...

I tried adding the two lines of code that were mentioned in your blog post but still it shows the date in en-US locale. The only way I can change the locale is if, at design time, I change the report rdl file language to some other locale. Any ideas?

Thomas said...

Thanks a lot for your solution.

Everybody is talking about CurrentThread's Culture but no one said that french (for exemple) is not part of default installation

Diego Correa said...

Thank you Martin, for your help, this article solved my problem.