How to process subreport of a subreport in rdlc?

与世无争的帅哥 提交于 2020-03-22 08:35:22

问题


I have an RDLC report which contains few sub reports. I am processing all those sub reports with LocalReport_SubreportProcessing event. Now out of these subreports, one report again has its sub report. I am not getting the idea how to process this sub report?

For main report, I have added an event.

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

Code for event

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);
    }
}

Code to process sub report of a sub report is as below:

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);
    }
}

回答1:


I have found the way to pass parameters to subreport of subreport:

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();
    }
}

Here, I have two datasets for the master report. They are passed in the constructor method, and filled in the load method along with the master report parameter.

In subreport processing, you need to discover who is subreport calling: subreport or subreport-of-subreport? Then you need to pass datasources to each one.




回答2:


@chirag Fanse: Sub report itself a report. When you are have a sub report(say A) of a sub report(say B) then now B will become your main report and A will be the sub report. So you can check the sub report like

if (e.ReportPath == "A")

and rest of the things will be same.



来源:https://stackoverflow.com/questions/17715245/how-to-process-subreport-of-a-subreport-in-rdlc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!