To set parameters on an RDLC report on Windows Forms, you can say viewer.LocalReport.SetParameters
and send in an array of ReportParameter
objects. However, what if you need to set parameter values on a subreport object? There is no way to call SetParameters
on the subreport object as far as I can tell. Google turned up several seemingly promising results for “rdlc subreport parameter” but none of them provided an answer.
I discovered a solution by trial and error. Here it is:
- Open the subreport and define parameters (say SR_P1, SR_P2)
- Open main report, insert a subreport object on it
- Define the corresponding parameters on the main report (MR_P1 and MR_P2)
- Right click on the subreport, select “Subreport Properties…”
- Select “Parameters” and add one row for each parameter
- Set each subreport parameter to the value of the corresponding main report parameter like this:
Name Value SR_P1 [@MR_P1] - In code, set the values of the main report parameters
MR_P1
andMR_P2
as usual usingviewer.LocalReport.SetParameters
You are welcome.