0
votes

I have a report that lists off taxes for a store given a storeID, a fromDate, and a toDate. I want to use this report as a subreport multiple times in the same parent report. For example, if you use storeID's 1,2,3,4,5 you would have this subreport show 5 times, with the first one having data for store 1, second one having data for store 2, etc.

Is this even possible? I've found some forums where people are asking how to use the same subreport twice in a report, but the threads always die out before they find something. I also saw you can use parameters but I'm not sure how those work (a bit new to sub-reporting in RDLC).

Thanks!

2

2 Answers

0
votes

If I understand correctly, probably you can use a single SubReport containing a Table displaying taxes grouped by store.

0
votes

In the main report, use 5 instances of the subreport. Change the (Name) property of each subreport, but keep the subreport path the same (as you already did).

When processing the main report, the method LocalReport_SubReportProcessing called many times according to instances count of the subreport found.

You'll make a global variable keeps the current store Id as in the code sampel below.

    public class TaxDetailsOfStore
    {
        public int StoreId { get; set; }

        // Your other details here...
    }

    // This global property be filled for all stores before displaying the main report.
    private List<TaxDetailsOfStore> TaxDetailsOfAllStores { get; set; }

    private int _storeId = 1; // To start with.
    private const int _maxStoreId = 5;

    private void LocalReport_SubReportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        string reportDataSourceName = string.Empty;
        object reportDataSourceValue = null;

        switch (e.ReportPath)
        {
            case "SubRprtTaxDetailsOfStore":
                int storeId = Convert.ToInt32(e.Parameters["storeId"].Values[0]);
                var lstTaxDetailsOfStore = TaxDetailsOfAllStores.FindAll(x => x.StoreId == storeId);

                //-------------------------------------------------------------------------------------
                // Increment the variable _storeId till reaches _maxStoreId and then back again from 1.
                _storeId = _storeId++ % _maxStoreId;
                //-------------------------------------------------------------------------------------

                reportDataSourceName = "TaxDetailsOfStoreDataSet";
                reportDataSourceValue = lstTaxDetailsOfStore;
                break;

            // Handle other sub reports like this.
            //case "SubRprtAnother1":
            //    object dsSubRprtAnother1 = null;
            //    reportDataSourceName = "AnotherDataSetName1";
            //    reportDataSourceValue = dsSubRprtAnother1;
            //    break;

            //case "SubRprtSummary":
            //    object dsSubRprtSummary = null;
            //    reportDataSourceName = "SubRprtSummaryDataSet";
            //    reportDataSourceValue = dsSubRprtSummary;
            //    break;
        }

        ReportDataSource reportDataSource = new ReportDataSource
        {
            Name = reportDataSourceName,
            Value = reportDataSourceValue
        };

        e.DataSources.Add(reportDataSource);
    }