Culture of thread for method render of LocalReport

為{幸葍}努か 提交于 2019-12-10 18:08:44

问题


I'm using a localreport object into an asp.net application. This report is fed by an array of object. So on the render of the report, some properties of the classe are called.

Class ClassForReport
{
  string Date
  {
    get{return _aDate.ToshortDateString();}
  }
}

Now the code for rendering and the problem:

//first of all, I change de culture for taking in account the choice of the user
CultureInfo ci = CultureInfo.CreateSpecificCulture(isoLanguageName_);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci; 
//Here, my culture is now: FR-be

MyLocalReport.render(...) // in this method, the property Date above is called. And when debugging I see that the culture is EN !!!

...
//and here, my culture is still Fr-be

So it seems that when the method render is called, it launch a thread and take the culture of the server and not the culture of the process.

The only workarround I see is changing my report to contains a date and then giving a parameter of culture and formating all my date in all my reports to the given culture...

So I realy hope there is a way to tell the report to take the curent culture of the asp thread and not taking some other culture comming from nowhere.

thx in advance


回答1:


In ".rdlc" Designer on your ReportFile, set on the Report in Language property "=User!Language".

<Report>
  ... 
  <Language>=User!Language</Language>
  ...
</Report>

then your System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE"); will work on the values in report.Render(...); like dates,etc.

Cheers.



来源:https://stackoverflow.com/questions/3164548/culture-of-thread-for-method-render-of-localreport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!