Generating report from rdlc xml string

给你一囗甜甜゛ 提交于 2021-02-07 08:19:32

问题


I'm facing an issue when generating reports.

I should generate report dynamically using all data from database for it (source name and rdlc report that stores as xml string)

So I solved problem next way:

  1. Create local rdlc file with report xml string;
  2. Set path to the file;

    var rViewer = new ReportViewer();
    rViewer.LocalReport.ReportPath = @"Path to the generated xml rdlc file";
    var dataSource = new ReportDataSource("DataSourceName", data);
    rViewer.LocalReport.DataSources.Add(dataSource);
    

Could I specify in the code-behind directly Report XML String instead of generating the rdlc file and set path to it? Could you recommend a better way?

Thank You


回答1:


Yes, You can provide it a StringReader object using LoadReportDefinition like so,

private void Page_Load(object sender, System.EventArgs e)
{
    NMBS.ViewModels.ViewModelReport Report = (Session["CurrentReport"] as NMBS.ViewModels.ViewModelReport);
ReportViewer.ProcessingMode = ProcessingMode.Local;
ReportViewer.PageCountMode = PageCountMode.Actual;

// Set report specifics.
ReportViewer.LocalReport.DisplayName = Report.Name;
ReportViewer.LocalReport.LoadReportDefinition(new System.IO.StringReader(Report.Definition));
foreach (ReportParameter Param in Report.Parameters)
{
    ReportViewer.LocalReport.SetParameters(Param);
}
foreach (ReportDataSource Rds in Report.Data)
{
    //Load Report Data.
    ReportViewer.LocalReport.DataSources.Add(Rds);
}
ReportViewer.CurrentPage = Report.CurrentPage;
ReportViewer.Width = Report.Width;

// Refresh the reports.
ReportViewer.LocalReport.Refresh();
}

Where Report.Defintion is the String containing the XML of the Report's Definition.



来源:https://stackoverflow.com/questions/17047278/generating-report-from-rdlc-xml-string

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