zoukankan      html  css  js  c++  java
  • ReportViewer动态加载RDLC报表文件

    I have a reportviewer control. I programmatically set the local report path based on a drop down on a page. This allows the user to choose which format (RDLC file) to use when generating the report.
    The first request, the report processes properly, however if I choose a different report format, the old report still renders. I'm doing a .refresh for the report...
    I tried turning off Viewstate for the report, but it says that Viewstate must be true for the ReportViewer control.
    If I "reenter" the page as new (such as by clicking on my menu item for that page), it will then run the first report type chosen.
    I'm changing the local report path such as  ReportViewer1.LocalReport.ReportPath = "myreport1.rdlc"
    or
    ReportViewer1.LocalReport.ReportPath = "myreport2.rdlc"

    Solution 1:

    使用多个ReportViewer,每个ReportViewer显示不同的RDLC。根据用户的选择显示一个ReportViewer,隐藏其他的ReportViewer。就在页面中添加多个ReportViewer控件来对应多个rdlc文件,然后根据需要显示和隐藏部分ReportViewer控件。

    Solution 2:

    Because there is no ReportViewer.Reset() in C#, the solution is to create an new instance of the report.  The trick is to Swap out the previous ReportViewer with the New ReportViewer.

    	ControlCollection cc = this.ReportViewer1.Parent.Controls;
    //get index of previous ReportViewer so we can swap it out.
    int prevIndex = cc.IndexOf(this.ReportViewer1);
    // Remove previous ReportViewer
    cc.Remove(this.ReportViewer1);
    //add new instance of ReportViewer.  
    ReportViewer1 = new Microsoft.Reporting.WebForms.ReportViewer();
    // Reset report properties.
    ReportViewer1.Height = Unit.Parse("100%");
    ReportViewer1.Width = Unit.Parse("100%");
    ReportViewer1.CssClass = "table";
    //Add the new ReportViewer to the previous ReportViewer location.
    cc.AddAt(prevIndex, ReportViewer1);
    // Clear out any previous datasources.
    this.ReportViewer1.LocalReport.DataSources.Clear();
    //Set report mode for local processing.
    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    // Create a new report dataset.
    DataSet dataSet = new DataSet();
    this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("ReportPeopleMailingList.rdlc");
    // Load dataset.
    try
    { 	// retrieve dataset.
    dataSet = (DataSet)Session["sessionDataSetCli"];	}
    catch
    {
    return;
    }
    // Assign report parameters.
    Microsoft.Reporting.WebForms.ReportParameter[] parms = new Microsoft.Reporting.WebForms.ReportParameter[1];
    parms[0] = new Microsoft.Reporting.WebForms.ReportParameter("title", "Clients");
    ReportViewer1.LocalReport.SetParameters(parms);
    // Load the dataSource.
    ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetPeople_adPeople", dataSet.Tables[0]));
    // Refresh the ReportViewer
    ReportViewer1.LocalReport.Refresh();
     
            Dim cc As ControlCollection = ReportViewer1.Parent.Controls
            Dim prevIndex As Integer = cc.IndexOf(ReportViewer1)
            cc.Remove(ReportViewer1)
            ReportViewer1 = New Microsoft.Reporting.WebForms.ReportViewer()
            ReportViewer1.Height = Unit.Parse("450px")
            ReportViewer1.Width = Unit.Parse("980px")
            cc.AddAt(prevIndex, ReportViewer1)
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.ReportPath = reportPath
            ReportViewer1.LocalReport.DataSources.Add(datasource)
            ReportViewer1.LocalReport.SetParameters(New ReportParameter() {.....})
            ReportViewer1.LocalReport.Refresh()
     
    Solution 3:

    Must do a

    ReportViewer1.Reset()

    ReportViewer1.LocalReport.Dispose()

    first. Then set your reportpaths, then do a
    ReportViewer1.LocalReport.Refresh()
    You must have VS2005 SP1 for this.

    From: 

    http://blog.csdn.net/qiujiahao/archive/2007/08/09/1733415.aspx

    http://objectmix.com/dotnet/304568-change-report-path-reportviewer-control.html

    http://66.129.67.4/t/1257010.aspx

    http://forums.asp.net/t/1183208.aspx

    http://social.msdn.microsoft.com/forums/en-US/vsreportcontrols/thread/c6524b68-bdfd-4f10-848f-355bc9445323/

    http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.aspnet.webcontrols/2008-07/msg00024.html

  • 相关阅读:
    VSTO开发指南(VB2013版) 第四章 Excel编程
    VSTO开发指南(VB2013版) 第三章 Excel编程
    VSTO开发指南(VB2013版) 第二章 Office解决方案介绍
    VSTO开发指南(VB2013版) 第一章 Office对象模型
    打印预览
    打印
    工具函数
    开始使用
    模版对应信息
    解决PLSQL或者sqlplus连接oracle慢的方法
  • 原文地址:https://www.cnblogs.com/emanlee/p/1291455.html
Copyright © 2011-2022 走看看