# Setting RDLC Subreport Parameters via Code

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:

1. Open the subreport and define parameters (say SR_P1, SR_P2)
2. Open main report, insert a subreport object on it
3. Define the corresponding parameters on the main report (MR_P1 and MR_P2)
4. Right click on the subreport, select “Subreport Properties…”
5. Select “Parameters” and add one row for each parameter
6. Set each subreport parameter to the value of the corresponding main report parameter like this:
Name Value
SR_P1 [@MR_P1]
7. In code, set the values of the main report parameters MR_P1 and MR_P2 as usual using viewer.LocalReport.SetParameters

You are welcome.