如何将另一个.rdlc报告传递给reportviewer

时间:2016-10-25 20:56:56

标签: printing rdlc reportviewer2008

我有一个带有下拉列表和文本框以及三个按钮的Web表单。 1)生成报告2)打印3)导出为PDF

我将printonebartest.rdlc作为绑定到reportviewer1的默认报告,专为用户正确查看信息而设计,但是当我打印相同的报告时,html会弄乱布局,所以我创建了另一个报告printonebartest1.rdlc,它被缩放到正确打印信息我的问题是如何在单击打印按钮并导出到pdf时将printonebartest1.rdlc传递给reportviewer1。

这是我打印按钮的代码

  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
        }

即使我通过printonebartest1.rdlc它仍然使用printonebartest.rdlc我在这里做错了什么,我是否必须重新绑定数据源或什么?请帮助任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您需要做的就是将'%'传递给您的where子句。对第一个请求的查询看起来与此类似,

从emp中选择*,其中名字为LIKE'%'。

因此,对于第一个请求,它将返回所有数据。后续的将基于传递的过滤器。

要确定这是否是第一个请求,我们始终可以使用IsPostBack属性。如果值为false,则这确实是第一个请求。如果不是这不是第一个请求。

除了第一次通过URL请求之外,使用F5 / CTRL + F5刷新浏览器时,该属性将为FALSE。