how to pass another .rdlc report into reportviewer

115 Views Asked by At

I have a web form with some drop down list and textbox and three buttons. 1) generate report 2) print 3) Export to PDF

I have printonebartest.rdlc as a default report binded to reportviewer1 which is designed for user to view the information correctly however when I print the same report the html messes up the layout so I created another report printonebartest1.rdlc which is scaled to print the information correctly my question is how can I pass printonebartest1.rdlc to reportviewer1 when the print button and export to pdf is clicked.

This is the code I have for the print button

  protected void Print_Click(object sender, ImageClickEventArgs e)
        {
            IolaNetWeightWeb.BarTableAdapters.Product_Weight_Data_Sheet_QueryTableAdapter ds = new IolaNetWeightWeb.BarTableAdapters.Product_Weight_Data_Sheet_QueryTableAdapter();
            ReportDataSource rds = new ReportDataSource("Bar_Product_Weight_Data_Sheet_Query", ds.GetData(DropDownList1.Text, DropDownList3.Text));

            // Variables
            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;


            // Setup the report viewer object and get the array of bytes
            ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportPath = "printonebartest1.rdlc";
            viewer.LocalReport.DataSources.Add(rds); // Add datasource here


            byte[] bytes = ReportViewer1.LocalReport.Render("Pdf", null, out mimeType, out encoding, out extension, out streamIds, out warnings);


            // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "inline; filename=PrintOneBar.pdf");
            Response.BinaryWrite(bytes); // create the file
            Response.Flush(); // send it to the client to download
        }

even though I am passing printonebartest1.rdlc it still uses the printonebartest.rdlc am I doing something wrong here, do I have to rebind the datasource or something? please help any help is appreciated.

1

There are 1 best solutions below

1
Ehayf2016 On

All you need to do is to pass ‘%’ to your where clause. The query for the first request will look something similar to this,

select * from emp where firstname LIKE ‘%’.

So for the first request it will return all the data. Subsequent ones will be based on the filter passed.

To determine if this is a first request we can always use the IsPostBack property. If the value is false, this is indeed a first request. If not this is not the first request.

The property will be FALSE when the browser is refreshed using F5 / CTRL + F5 apart from the first request through URL.