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

  • 相关阅读:
    Django开发笔记一
    Netty+SpringBoot写一个基于Http协议的文件服务器
    SQL优化
    mysql 字符串数字转换
    git 常用的命令总结
    eclipse 使用Maven deploy命令部署构建到Nexus
    intellij idea远程debug调试resin4教程
    postman 请求种添加用户权限
    对List中每个对象元素按时间顺序排序
    List根据时间字符串排序
  • 原文地址:https://www.cnblogs.com/emanlee/p/1291455.html
Copyright © 2011-2022 走看看