I've a class that contains methods to set up several reports. The reports
are all different views of the same data set, so it seemed logical to have a
class to generate the dataset just once and provide methods to deliver each
report as it's needed.
The report used by the following function has a single subreport. I set up
an event handler for when the subreport needs to be built.
My worry is, if the same reportviewer control is passed into the function,
is it accumulating a stack of reportviewer.localreport.SubreportProcessing
event handlers somewhere?
I considered adding reportViewer.LocalReport.SubreportProcessing -=
DailySubreportProcessingEventHandler; at the end, but reports are rendered
asynchronously so this wasn't a good solution
If event handlers are stacking then how do I clear the list before adding a
new event handler please
public void DailyReport(Int64 userID, Int32 siteID,
DateTime StartDate, DateTime EndDate, ReportViewer reportViewer)
{
const string fnName = "DailyReport";
try
{
CreateDatasets(userID, siteID, StartDate, EndDate);
// Localize the reports
string ReportPath =
ReportHandler.LocalizeAndWriteReportToFile("rptDaily.rdlc");
ReportHandler.LocalizeAndWriteReportToFile("rptDaily_SubReport.rdlc");
// Set up the report viewer
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.ReportPath = ReportPath;
reportViewer.LocalReport.SubreportProcessing +=
DailySubreportProcessingEventHandler;
// Set up report datasource for the repors for users
ReportDataSource rds = new ReportDataSource {Name =
"datasetResults_dtUsers", Value = usersTable};
reportViewer.LocalReport.DataSources.Add(rds);
// Set up report datasource for the report for results
rds = new ReportDataSource {Name = "datasetResults_dtResults", Value
= resultsTable};
reportViewer.LocalReport.DataSources.Add(rds);
// Reload the report into the viewer
reportViewer.RefreshReport();
}
catch(Exception e)
{
LogException(fnName, e);
throw;
}
#endregion
}// function
private void DailySubreportProcessingEventHandler(object sender,
SubreportProcessingEventArgs e)
{
e.DataSources.Add(new ReportDataSource("datasetResults_dtResults",
resultsTable));
}
> Hi
>
> I've a class that contains methods to set up several reports. The
> reports are all different views of the same data set, so it seemed
> logical to have a class to generate the dataset just once and provide
> methods to deliver each report as it's needed.
> The report used by the following function has a single subreport. I set
> up an event handler for when the subreport needs to be built.
>
> My worry is, if the same reportviewer control is passed into the
> function, is it accumulating a stack of
> reportviewer.localreport.SubreportProcessing event handlers somewhere?
> I considered adding reportViewer.LocalReport.SubreportProcessing -=
> DailySubreportProcessingEventHandler; at the end, but reports are
> rendered asynchronously so this wasn't a good solution
> If event handlers are stacking then how do I clear the list before
> adding a new event handler please
It's not clear to me that you want to "clear the list". Instead, you seem
to actually want to remove the event handler once it's been run. Assuming
that's the case, why not have the handler remove itself?
If that doesn't address the question, then you should post a
concise-but-complete code example that reliably demonstrates the problem.
Note that since your question really doesn't have anything to do with the
reporting per se, your example would not include any reference to the
reporting; instead, it would provide the bare minimum to demonstrate how
the event is being used and what you want to do with it, all while being a
_complete_ code sample that can be compiled and run.
Pete