Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a similar situation to you were I have services that can create a Local Report which can then be generated into a PDF, emailed, etc. However, because ReportViewer.LocalReport is a read-only property I had to either duplicate the code used to build the report or copy the values from my LocalReport to the ReportViewer.LocalReport. I'm not a fan of either option because either something might not get copied (i.e. sub reporting event) or there is code duplication.</p> <p>I came up with the following extension that sets the LocalReport on a ReportViewer with reflection. I have not fully tested this and it may be a bad idea! However, it seems to work for the project I'm currently working on. I have no idea if the ReportViewer does some additional initialization of it's local report so something might blow up....</p> <p><strong>I CAN'T STRESS THIS ENOUGH -- USE AT YOUR OWN RISK - PROBABLY NOT A GOOD IDEA TO DO THIS</strong></p> <pre><code>public static class ReportViewerExtensions { public static void SetLocalReport(this ReportViewer reportViewer, LocalReport report) { var currentReportProperty = reportViewer.GetType().GetProperty("CurrentReport", BindingFlags.NonPublic | BindingFlags.Instance); if (currentReportProperty != null) { var currentReport = currentReportProperty.GetValue(reportViewer, null); var localReportField = currentReport.GetType().GetField("m_localReport", BindingFlags.NonPublic | BindingFlags.Instance); if (localReportField != null) { localReportField.SetValue(currentReport, report); } } reportViewer.RefreshReport(); } } </code></pre> <p>Usage:</p> <pre><code>LocalReport localReport = reportService.GenerateCurrentOrdersReport(....); reportViewer.SetLocalReport(localReport); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload