如何在rdlc中处理子报表的子报表?

时间:2013-07-18 05:33:39

标签: asp.net reporting-services rdlc

我有一份RDLC报告,其中包含很少的子报告。我正在使用LocalReport_SubreportProcessing事件处理所有这些子报告。现在,在这些子报告中,一份报告再次有其子报告。我不知道如何处理这个子报告?

对于主报告,我添加了一个事件。

viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
    viewer.LocalReport.Refresh();

活动代码

void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{      
    if (e.ReportPath == "rpt_PSRUserHoursDetail")
    {
        //Code
    }
    else if (e.ReportPath == "rpt_BEnchMiscDetails")
    {

        System.Data.DataTable dtBenchMiscSubReport =DataTable
        ReportDataSource subRptSource = new ReportDataSource("DataSource", dtBenchMiscSubReport);
        e.DataSources.Add(subRptSource);

        (sender as Microsoft.Reporting.WebForms.LocalReport).SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessingBench);

        CommonHelper.DisposeOf(dtBenchMiscSubReport);
    }
}

处理子报告子报告的代码如下:

void LocalReport_SubreportProcessingBench(object sender, SubreportProcessingEventArgs e)
{
    int intProjectID = 0;
    int int_UserID = 0;

    if (e.Parameters.Count > 0 && e.ReportPath=="SubMiscellaneousTaskReport")
    {
        //get parameter

    }

    DateTime dtCurrentMonth = clsCheckDBNull.ToDate(string.Format("{0}-{1}-{2}", drpYear.SelectedValue, drpMonth.SelectedValue, "01"));
    if (e.ReportPath == "SubMiscellaneousTaskReport")
    {
        System.Data.DataTable dt = DataTable
        ReportDataSource subRptSource = new ReportDataSource("Dataset1", dt);
        e.DataSources.Add(subRptSource);
    }
}

2 个答案:

答案 0 :(得分:1)

我找到了将参数传递给子报表子报表的方法:

public partial class FormReportViewerAsnDetailed : Form
{
    private readonly int PoID;

    public FormReportViewerAsnDetailed(int PoID)
    {
        this.PoID = PoID;
        InitializeComponent();
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", bindingSource1));
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", bindingSource2));
        reportViewer1.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing;
    }

    private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        if (e.Parameters.Any(k => k.Name == "AsnID")) //is it asn subreport?
        {
            var asn = int.Parse(e.Parameters["AsnID"].Values.First());

            asn_Details_ReportTableAdapter1.Fill(viewAsnDetailsDataSet1.Asn_Details_Report, asn);
            e.DataSources.Add(new ReportDataSource("DataSet2",
                new BindingSource(viewAsnDetailsDataSet1, "Asn_Details_Report")));

            inbound_By_AsnTableAdapter1.Fill(inboundsReportDataSet1.Inbound_By_Asn, asn);
            e.DataSources.Add(new ReportDataSource("DataSet1",
                new BindingSource(inboundsReportDataSet1, "Inbound_By_Asn")));
        }
        else // subreport of subreport
        {
            inbound_Items_ReportTableAdapter1.Fill(inboundItemsReportDataSet1.Inbound_Items_Report,
                int.Parse(e.Parameters["InboundID"].Values.First()));
            BindingSource src = new BindingSource(inboundItemsReportDataSet1, "Inbound_Items_Report");
            e.DataSources.Add(new ReportDataSource("DataSet1", src));
        }
    }

    private void FormReportViewer_Load(object sender, EventArgs e)
    {
        this.purchase_Order_Details_ReportTableAdapter1.Fill(
            purchaseOrderDetialsReport1.Purchase_Order_Details_Report, PoID);
        asn_Select_By_POTableAdapter1.Fill(asnDetailedList1.Asn_Select_By_PO, PoID);
        reportViewer1.LocalReport.SetParameters(new ReportParameter("po", PoID.ToString()));
        this.reportViewer1.RefreshReport();
    }
}

这里,我有两个主报告数据集。它们在构造函数方法中传递,并与主报表参数一起填充加载方法。

在子报表处理中,您需要发现谁是子报表调用:subreport或subreport-of-subreport?然后你需要将数据源传递给每一个。

答案 1 :(得分:0)

@chirag Fanse:Sub报告自己的报告。如果您有子报告(例如A)的子报告(例如A),那么现在B将成为您的主报告,A将成为子报告。所以你可以查看子报告,如

if (e.ReportPath == "A")

其余的事情都是一样的。