【问题标题】:SSRS - Sub report within a sub reportSSRS - 子报告中的子报告
【发布时间】:2019-03-10 22:22:20
【问题描述】:

我正在构建一个用户可以导出的报告,但我遇到了一些困难。我很想得到一些人的意见,因为我开始有点灰心了。


问题

我有 CalcTable 存储 CalcTableMonthly 的父行。要从CalcTable 检索行,我使用标识符LeaseID。然后由于CalcTable 中有多个行在一个LeaseID 之下,CalcTable 中的每一行将在CalcTableMonthly 中有多个月度值。

MainReport 通过LeaseIDCalcTable 获取值。

SubReport1 再次通过LeaseIDCalcTableMonthly 获取值。这些值是在CalcTableMonthly 中具有值的所有可用CalcTable 行的组合。

然后最后SubReport2 获取该月的所有组合值。所以我必须从 SubReport1 中传入LeaseIDMonth

所以你可以看到它在第 2 级时有效。

页面加载

 protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            // Get LeaseID from query string
            sqls_Summary.SelectParameters["LeaseID"].DefaultValue = Request["LeaseID"];
            // Set report path
            this.rep_Main.LocalReport.ReportPath = "Reports\\CalculationReports\\rpt_Summary_Export.rdlc";
            // Set Report DataSources
            this.rep_Main.LocalReport.DataSources.Add(new ReportDataSource("dsLeaseCalculations", sqls_Summary));
            this.rep_Main.LocalReport.DataSources.Add(new ReportDataSource("dsLeaseCalculationsMonths", sqls_Summary_Months));
            this.rep_Main.LocalReport.DataSources.Add(new ReportDataSource("dsLeaseCalculationsViewMonth", sqls_Summary_ViewMonth));
            // Set the subreport processing event.
            this.rep_Main.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(subReportProccessingFunc);
            this.rep_Main.LocalReport.Refresh();
        }

    }

子报表处理事件

public void subReportProccessingFunc(object sender, SubreportProcessingEventArgs e)
    {
        sqls_Summary_Months.SelectParameters["LeaseID"].DefaultValue = e.Parameters["prmLeaseID"].Values.First();
        e.DataSources.Add(new ReportDataSource("dsLeaseCalculationsMonths", sqls_Summary_Months));

        sqls_Summary_ViewMonth.SelectParameters["LeaseID"].DefaultValue = e.Parameters["prmLeaseID"].Values.First();
        sqls_Summary_ViewMonth.SelectParameters["Month"].DefaultValue = // What to put here????
        e.DataSources.Add(new ReportDataSource("dsLeaseCalculationsViewMonth", sqls_Summary_ViewMonth));
    }

从上面的代码行sqls_Summary_ViewMonth.SelectParameters["Month"].DefaultValue =我不确定如何处理。如何从 RDLC 报告的当前行中检索月份?

我尝试过的事情

  1. 谷歌搜索类似问题,找不到任何东西
  2. 将 DefaultValue 设置为 e.Parameters["LiabilityDate"].Values.First() 不起作用,因为它没有获取值。

就是这样,因为我真的不知道......


总结

我有 1 个主报表,该主报表有一个子报表,该子报表有另一个子报表。为了检索子报表,我只将 LeaseID 值传递给它。第一个子报表也只需要 LeaseID 但是位于第一个子报表中的第二个子报表需要 LeaseID AND月份。我不确定如何在 RDLC 的子报表中获取本月变量,因为它在报表生成器中的 rdl 中工作,如下图所示,但遗憾的是当我在 ASP.net 中使用它时无法工作

【问题讨论】:

    标签: c# asp.net reporting-services ssrs-2008 rdlc


    【解决方案1】:

    经过一番修整并离开我的办公桌后,我想到了一个解决方案。

    我在第一个函数中创建了另一个 SubreportProcessingEventHandler。

    public void subReportProccessingFunc(object sender, SubreportProcessingEventArgs e)
    {
       sqls_Summary_Months.SelectParameters["LeaseID"].DefaultValue = 
       e.Parameters["prmLeaseID"].Values.First();
       e.DataSources.Add(new ReportDataSource("dsLeaseCalculationsMonths", 
       sqls_Summary_Months));
    
       this.rep_Main.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(subReportProccessingFunc1);
    }
    
    public void subReportProccessingFunc1(object sender, SubreportProcessingEventArgs e)
    {
       sqls_Summary_ViewMonth.SelectParameters["LeaseID"].DefaultValue = e.Parameters["prmLeaseID"].Values.First();
       sqls_Summary_ViewMonth.SelectParameters["Month"].DefaultValue = e.Parameters["prmMonth"].Values.First();
       e.DataSources.Add(new ReportDataSource("dsLeaseCalculationsViewMonth", sqls_Summary_ViewMonth));
    }
    

    因此,一旦处理了第一个子报表,第二个子报表就会再次像主报表一样工作,而另一个子报表将在其位置处理。我能够为该行选择 prmMonth 值并且一切正常!

    希望它可以帮助任何偶然发现此问题的人!

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多