none
Adding subreport to main report at runtime (RDLC)

    Question

  • I am working on reporting application and according to requirement I need to generate and add subreports at run time.
    For this, I have  created one dummy application which have main report added. Now I am creating new report and adding it as sub report at run time.
    The report which is created at run time have only one text box and nothing else.
    But still it gives me error that -: "Error: subreport cannot be shown.".
    When I run the report seperately it works fine.

    Can anybody help me to softout this problem?

    Note: I am working on C# 2008 AND local reporting i.e. RDLC and not RDL
    Wednesday, July 01, 2009 12:31 PM

Answers

  • Hi Hemant,

     

    From your description, you created a report and add added it as sub report at runtime. However, the ReportViewer control throws the exception “Error: subreport cannot be shown”. If there is anything I have misunderstood, please let me know.

     

    First, if we want to load a sub report, we must re-bind the ReportDataSource through code in the event, unless we will get the error “Error: subreport cannot be shown”.

    Second, if we use an embed Subreport Control, we use the event “ReportViewer_SubreportProcessing”. But if we load sub report using DrillThrough, we must use the event “ReportViewer_Drillthrough”.

    Overall, we can use re-bind the ReportDataSource in the “Drillthrough” to archive this require:

     private void reportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)  

     

            {  

     

                LocalReport localReport = (LocalReport)e.Report;  

     

       

     

                localReport.DataSources.Add(new ReportDataSource("OrderDetailsDataSet_OrderDetails", OrderDetailsDataSet.Tables[0]));  

     

            }  

     

     

    If the solution above does not help, could you please upload the sample for future research.

     

    Thanks,

    Jin Chen


    Jin Chen - MSFT
    Tuesday, July 07, 2009 10:21 AM
    Moderator

All replies

  • Hi Hemant,

     

    From your description, you created a report and add added it as sub report at runtime. However, the ReportViewer control throws the exception “Error: subreport cannot be shown”. If there is anything I have misunderstood, please let me know.

     

    First, if we want to load a sub report, we must re-bind the ReportDataSource through code in the event, unless we will get the error “Error: subreport cannot be shown”.

    Second, if we use an embed Subreport Control, we use the event “ReportViewer_SubreportProcessing”. But if we load sub report using DrillThrough, we must use the event “ReportViewer_Drillthrough”.

    Overall, we can use re-bind the ReportDataSource in the “Drillthrough” to archive this require:

     private void reportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)  

     

            {  

     

                LocalReport localReport = (LocalReport)e.Report;  

     

       

     

                localReport.DataSources.Add(new ReportDataSource("OrderDetailsDataSet_OrderDetails", OrderDetailsDataSet.Tables[0]));  

     

            }  

     

     

    If the solution above does not help, could you please upload the sample for future research.

     

    Thanks,

    Jin Chen


    Jin Chen - MSFT
    Tuesday, July 07, 2009 10:21 AM
    Moderator
  • Hi Jin,

    Sorry for late reply.
    As I mentioned in my previous post that the subreport have only one text box and nothing else. According to my knowledge it does not required any kind of datasource.
    Still in this case we required to add datasource in report?

    2nd thing, I am not using drill through facility.
    I am just adding sub report(which is also generated at run time) having only one text box in the main report at run time.

    If the above clarification does not help you then i will send you the sample code to you.

    Regards,
    Hemant

    Wednesday, October 21, 2009 1:18 PM
  • Hi Hemant,

    i am new to rdlc and have a really basic question for you.

    how can i add multiple instances of subreports to a rdlc at runtime?

    say i have a report that lists employers and i create a subreport that lists all employees for a particular empoyer. is it then possible on one rdlc to have the list of employers and a bunch of subreports for each employer's employees?

    Thanks,

    Yash
    Tuesday, January 26, 2010 11:43 PM
  • hi Jin Chen,

     I was trying to create Sub Report Based on the parameter from the Main report column in RDLC 2010.. but im getting the same result on all the rows could you help me to solve this..?

    following are the code:

     this.rptProject.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);

        public void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
            {      

                  // count performes the index value based on the parameter

                e.DataSources.Add(new ReportDataSource("DataSet_GetProjectCategory",  BindProjectCategory(objReasonList[count].Reason_Id)));

            }
    Friday, August 24, 2012 6:44 AM