3
votes

Using ReportViewer i want to render multiple reports in one pdf using rdlc file.

Byte pdfByte = Byte();
pdfByte = ReportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extensions, stream, warning);
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=myfile." + extension);
Response.BinaryWrite(pdfByte);
Response.Flush();
Response.End();

This only generate only one report in pdf. But i want to get multiple reports rendered in one pdf file.

Please help me.

2
Just a friendly tip, you may want to read over this page: The How-To-Ask Guide so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your show code and any error messages!Matt C

2 Answers

5
votes

The easiest way to do this would be to design all the reports to be sub-reports of one main report. Then, by default all reports will be rendered in one PDF.

There's a couple of videos demonstrating sub-reports here: Part 1 & Part 2

If you can't structure your reports into sub-reports, then there is good & bad news...

Bad news: there's no straightforward way to achieve this in the framework.

Good news: it's possible by using the PDFsharp 3rd-party library. It's open source & free to use, even in commercial applications.

See previous question: Rendering multiple .rdlc reports into a single PDF using PDFSharp

Good luck!

0
votes

I have dealt with this issue for a few days, but I finally found a solution. Clicking one of the two buttons in a form will load the corresponding report. I hope it works for those interested :)

Solution Name : GelirGiderYonetimi

private void giderBtn_Click(object sender, EventArgs e)
    {
        giderPnl.Visible = true; gelirPnl.Visible = false;
        this.GiderTableAdapter.Fill(this.giderDS.Gider);
        ReportDataSource r = new ReportDataSource("DataSet1", giderDS.Tables[0]);
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.DataSources.Add(r);
        this.reportViewer1.LocalReport.ReportEmbeddedResource = "GelirGiderYonetimi.giderRapor.rdlc";
        this.reportViewer1.LocalReport.Refresh();
        this.reportViewer1.RefreshReport();
    }

    private void gelirBtn_Click(object sender, EventArgs e)
    {
        giderPnl.Visible = false; gelirPnl.Visible = true;
        this.GelirTableAdapter.Fill(this.gelirDS.Gelir);

        ReportDataSource r = new ReportDataSource("DataSet1", gelirDS.Tables[0]);
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.DataSources.Add(r);
        this.reportViewer1.LocalReport.ReportEmbeddedResource = "GelirGiderYonetimi.gelirRapor.rdlc";
        this.reportViewer1.LocalReport.Refresh();
        this.reportViewer1.RefreshReport();
    }