Pass parameter to a .rdlc report file

2011-03-08


How to pass a parameter to a .rdlc file?

Steps:

1: In Visual Studio 2010, open your .rdlc file, and open "Report Data" window (If you can not see this window, go to View menu to open it);

2: Right click the "Parameters" node, and add a new Parameter, ie: named it "content";

3: In your .rdlc file, add a textbox, named it tbContent, and set its filed express to:

=Parameters!content.Value

4: Go to your Form file which include your reporterview control, and add the following code:

           this.reportViewer1.LocalReport.ReportEmbeddedResource = "TestReport.Report1.rdlc";
            ReportParameter rp = new ReportParameter("content", this.textBox1.Text);
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
            this.reportViewer1.RefreshReport();

5: then you can pass the parameter from the TextBox on the form to .rdlc file;