The following code resides inside a method and it uses the report viewer to render reports:
objReportViewer.LocalReport.ReportPath = "TestReport.rdlc";
objReportViewer.LocalReport.DataSources.Clear();
objReportViewer.LocalReport.DisplayName = "TestReport_" + DateTime.Now.ToString("yyyyMMdd");
object objReportDataSource = TestReportDataSource(Id);
objReportViewer.LocalReport.DataSources.Add(new ReportDataSource("TestReportDataSource", objReportDataSource));
objReportViewer.ZoomMode = ZoomMode.PageWidth;
ReportParameter[] arrReportParameters = new ReportParameter[3];
// First Name
arrReportParameters[0] = new ReportParameter("FirstName",person.FirstName);
// LastName
arrReportParameters[1] = new ReportParameter("LastName", person.LastName);
//DOB
arrReportParameters[2] = new ReportParameter("Age",person.DOB);
objReportViewer.ShowParameterPrompts = false;
objReportViewer.DocumentMapCollapsed = true;
objReportViewer.ShowDocumentMapButton = false;
objReportViewer.LocalReport.SetParameters(arrReportParameters);
objReportViewer.LocalReport.ExecuteReportInSandboxAppDomain();
objReportViewer.LocalReport.Refresh();
So far no issues when trying to generate the reports, if there is a lot of information then the report will have two or more pages. If I want to print or export to .pdf I can do so from the rendered report. My questions are two:
1- How can I make the report viewer export to .pdf programmatically.
2- How can I make the report viewer show only 1 page ignoring the rest of the data, or in case of exporting it to .pdf programmatically how can I export only the first page ignoring the rest.
For example if a report would normally render 2 pages I want it to render only the first one.
Is it possible to accomplish using the report viewer?
Thank you.