【问题标题】:how can I user one Report Viewer for different RDLC/Reports如何为不同的 RDLC/报告使用一个报告查看器
【发布时间】:2013-12-21 05:36:42
【问题描述】:

我想对所有 rdlc 文件使用一个报告查看器控件。所有 rdlc 报告都有一些常见和一些不常见的参数或搜索条件。

有人知道我怎样才能做到这一点吗?我不希望针对不同的报表使用不同的报表查看器控件。

谢谢

【问题讨论】:

    标签: .net reporting-services rdlc


    【解决方案1】:

    您可以在运行时设置 ReportViewer 控件的各个方面。

    设置正确的rdlc文件:

    YourReportViewerControl.LocalReport.ReportPath = <path to your rdlc file>
    

    在运行时添加参数:

    Dim parA As New ReportParameter("parA", "this is A")
    Dim parB As New ReportParameter("parB", "this is B")
    
    YourReportViewerControl.LocalReport.SetParameters(New ReportParameter() {parA, parB})
    

    在运行时添加数据源:

    YourReportViewerControl.LocalReport.DataSources.Add(New ReportDataSource("yourDataSourceName", YourDataSource))
    

    因此,您只能为发送到 ReportViewer 的 rdlc 设置正确的参数/数据集。

    【讨论】:

      【解决方案2】:

      下面的代码可用于在单个报表查看器中使用多个 rdlc 文件。

      //添加此代码以在运行时嵌入报表

          reportViewer1.Reset();
          reportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewer.Report2.rdlc";
          this.reportViewer1.RefreshReport();
      

      //reportViewer1--> 报表查看器控件

      //ReportViewer --> 解决方案的名称

      //Report2.rdlc --> 报告名称

      【讨论】:

      • 请记住,我对每个报告都有不同的参数。所以这不适用于这种情况。
      【解决方案3】:
      try this 
       ReportViewer1.LocalReport.ReportPath = @"Your\report\path.rdlc";
                  ReportViewer1.LocalReport.DataSources[x] = "datasourceID";
                  ReportViewer1.LocalReport.Refresh(); 
      in Asp.net
      
      for windows form
      
       ReportViewer1.LocalReport.ReportPath = @"Your\report\path.rdlc";
                  ReportViewer1.LocalReport.DataSources[x] = "datasourceID";
                  ReportViewer1.RefreshReport(); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-14
        • 1970-01-01
        • 2016-01-10
        • 1970-01-01
        • 1970-01-01
        • 2014-06-24
        相关资源
        最近更新 更多