Sub Reports

28 posts, 0 answers
  1. Bhaskar
    Bhaskar avatar
    2 posts
    Member since:
    Nov 2007

    Posted 19 Dec 2007 Link to this post

    Hi,
         I have been evaluating Telerik reports for a few days now. I like what I have seen so far. I need to know one thing before I make a final decision. We have a requirement to merge different reports and export them in PDF format. The number of reports and type of reports vary depending on users search criteria.
        I know we can add sub report items programmatically. Is there a limit on the number of sub report items you can add programmaitcally. If so what is the limit. Also do you have any samples in C# that will show me how to add sub report items programmatically.
           I created a small sample that creates sub report items programmatically. In the report viewer it's showing okay. But when I export it to PDF format the sub report items are overlapping. 

    Thanks
    Bhaskar
  2. Milen
    Admin
    Milen avatar
    163 posts

    Posted 20 Dec 2007 Link to this post

    Hello Bhaskar,

    Here you can see a code snippet on how to create a report at runtime that combines several other reports.

            private void buttonView_Click(object sender, EventArgs e)
            {
                List<Report> detailReports = new List<Report>();
                detailReports.Add(new Report1());
                detailReports.Add(new Report3());
                detailReports.Add(new Report4());
                detailReports.Add(new Report2());

                Report report = GetCombinedReport(detailReports);
                reportViewer1.Report = report;
                reportViewer1.RefreshReport();
            }

            private static Report GetCombinedReport(List<Report> detailReports)
            {
                Report report = new Report();
                DetailSection detail = new DetailSection();
                report.Items.Add(detail);

                Unit unitX = Unit.Inch(0.1);
                Unit unitY = Unit.Inch(0.1);
                SizeU size = new SizeU(Unit.Inch(1), Unit.Inch(0.5));
                foreach (Report detailReport in detailReports)
                {
                    SubReport subReport;
                    subReport = new SubReport();
                    subReport.Location = new PointU(unitX, unitY);
                    subReport.Size = size;
                    unitY = unitY.Add(Unit.Inch(1));
                    subReport.ReportSource = detailReport;
                    detail.Items.Add(subReport);
                }
                detail.Height = Unit.Inch(detailReports.Count + 1);
                return report;
            }

    Probably not setting Location and/or Size of SubReport items would produce overlapped items.

    Unfortunately, while creating your example we found a new bug introduced in the new version Q3 2007. A section longer then one page does not render properly. This problem will be fixed in the beginning of January 2008. We are sorry for the inconvenience.

    Do not hesitate to contact us if you have any other questions.

    Kind regards,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. DevCraft banner
  4. Bhaskar
    Bhaskar avatar
    2 posts
    Member since:
    Nov 2007

    Posted 26 Dec 2007 Link to this post

    Thanks Milen. I will let you know if I have any further questions. I hope they fix the bug you mentioned soon. I will have reports whose section will span more than one page.

    Bhaskar.
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 Dec 2007 Link to this post

    Hello Bhaskar,

    We apologize for the late reply.

    The bug will be fixed for the Service Pack which will be released in the first half of January.

    Greetings,
    Ross
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Madu
    Madu avatar
    7 posts
    Member since:
    Jul 2007

    Posted 21 Jan 2008 Link to this post

    hi,
    can you please tell me how should i use a subreport inside a master report.
    and bind its data.

    regards,
    madu
  7. Milen
    Admin
    Milen avatar
    163 posts

    Posted 22 Jan 2008 Link to this post

    Hi Madu,

    As your question is too general, maybe you should first take a look at this help article.

    There are more then one way to show relevant data in the subreport to the master report.

    Let's suppose we have Invoice/InvoiceDetail reports.

    First approach - to use report parameters in the detail report:
    1. In the InvoiceDetail report set up a datasource that pulls out all the detail rows.
    2. Set up a parameter(s) in InvoiceDetail report to be used in filter expression, for example InvoiceID.
    3. Set up a Filter in the InvoiceDetail report that uses InvoiceID parameter to filter the rows
    4. Rebuild
    5. In the master report place a SubReport item in the details section and choose InvoiceDetail as ReportSource.
    6. Set up the parameters of the SubReport item to pass the value of Fields.CustomerID to the CustomerID parameter of InvoiceDetail report.

    Second approach - to use the NeedDataSource of the SubReport item:
    Use the NeedDataSource event of the SubReport item placed on the master report to retrieve the relevant detail data to the current master row and pass that data as a DataSource of the detail report. Something like:

    Private Sub SubReport1_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubReport1.NeedDataSource

    //This is the way to get the SubReport processing item in the current detail section
    Dim subreport as Telerik.Reporting.Processing.SubReport = TryCast(sender, Telerik.Reporting.Processing.SubReport)

    //This is the way to get the current master row
    Dim row as DataRow = (TryCast(subReport.DataItem, System.Data.DataRowView)).Row

    //Retrieve detail data for the current detail row
    Dim connectionString As String = "Data Source=***;Initial Catalog=***;Persist Security Info=True;User ID=***;Password=***"

    Dim commandText As String = "SELECT StockName, Qty, Price FROM InvoiceDetails WHERE InvoiceID = " & row("CustomerID")

    Dim da As SqlDataAdapter = New SqlDataAdapter(commandText, connectionString)

    subreport.InnerReport.DataSource = da

    End Sub

    Also, you can use the SubReport item to create reports binded to business objects. If that is the case you can also use the NeedDataSource event to provide data to the detail report.

    Please review the article mentioned above, try the patterns shown here and write us again if you have more specific questions.

    Kind regards,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 28 Apr 2008 Link to this post

    I've tried the second method that you've shown and it appears to work pretty well. The problem I've having is that I have 4 records in the datasource that is bound to the main report. I expected the the NeedsDataSource event handler in the subreport would be called each time the report is run, but it appears to only call it once and return the same results 4 times. What do I need to do to force it to update the report each time?
  9. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 29 Apr 2008 Link to this post

    Hello Adam,

    The NeedDataSource event of the main report is called only once. The NeedDataSource event of a SubReport item is call as many times as is the row count in the data source for the main report. Please, make sure that you handle the events correctly. If it still doesn't work as expected please open a support ticket and send us the report definitions so that we can review them.

    Best wishes,
    Chavdar
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 29 Apr 2008 Link to this post

    I believe I've found the problem. I was using the NeedDataSource handler that was inside of the subreport. When I changed it to the NeedDataSource for the subreport but is placed in the main report, the problem seems to have resolved itself.

    Thanks for the quick response as usual.
  11. Maveric
    Maveric avatar
    39 posts
    Member since:
    Apr 2007

    Posted 29 Sep 2008 Link to this post

    Hi,

    I used the code give by Milen to create a report at runtime that combines several other reports.
    It's perfect but I want to add in the footer of each page the number of the page and total number of page. How can i make that ?
    Another question : How to force a subreport to go to a new page ?

    Thanks

    Eric
  12. Milen
    Admin
    Milen avatar
    163 posts

    Posted 30 Sep 2008 Link to this post

    Hello Maveric,

    You can add a TextBox item to the PageFooter and set its value to "= PageNumber + ' of ' + PageCount", and this way you will have the current page and the total pages count. There is no way to have a page counter that is reset when a new sub-report begins.

    To force a page break before each sub-report you can add a ReportHeader section to the report used as a sub-report and set the PageBreak property of this section to Before. However keep in mind that this page break (nested) is not currently respected in the HTML rendering extension, but will be respected in all other extensions (including printing).

    Hope you find that information helpful.

    Regards,
    Milen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Maveric
    Maveric avatar
    39 posts
    Member since:
    Apr 2007

    Posted 02 Oct 2008 Link to this post

    Hi Milen,

    Thanks for your answer.
    It's Ok with the page break but I have problem with the pagefooter
    I have the following error :
    #ERROR# The expression contains object 'PageNumber' that is not defined in the current context.

    below the code I use
    Do you see where is my error ?


     Public Shared Function GetCombinedReport(ByVal detailReports As List(Of Report)) As Report 
            Dim report As New Report() 
            Dim detail As New DetailSection() 
            Dim footer As New ReportFooterSection 
            Dim textBox1 As New Telerik.Reporting.TextBox() 
     
            report.Items.Add(detail) 
     
            Dim unitX As Drawing.Unit = Drawing.Unit.Inch(0.1) 
            Dim unitY As Drawing.Unit = Drawing.Unit.Inch(0.1) 
            Dim size As New Drawing.SizeU(Drawing.Unit.Inch(1), Drawing.Unit.Inch(0.5)) 
     
            For Each detailReport As Report In detailReports 
                Dim subReport As SubReport 
                subReport = New SubReport() 
                subReport.Location = New Drawing.PointU(unitX, unitY) 
                subReport.Size = size 
                unitY = unitY.Add(Drawing.Unit.Inch(0.8)) 
                subReport.ReportSource = detailReport 
                detail.Items.Add(subReport) 
            Next 
            detail.Height = Drawing.Unit.Inch(detailReports.Count + 1) 
            textBox1.Value = "= 'Page ' + PageNumber + ' de ' + PageCount" 
            textBox1.Left = Drawing.Unit.Cm(15) 
            textBox1.Size = New Drawing.SizeU(Drawing.Unit.Inch(1), Drawing.Unit.Inch(0.5)) 
            footer.Items.Add(textBox1) 
            report.Items.Add(footer) 
            Return report 
        End Function 

  14. Milen
    Admin
    Milen avatar
    163 posts

    Posted 02 Oct 2008 Link to this post

    Hello Maveric,

    The PageNumber and PageCount variables can be accessed only in page sections (PageHeaderSection and PageFooterSection). In your code snipped you are trying to use them in a ReportFooterSection. This causes the error. Most probably you need a PageFooterSection to display the PageNumber on every page and not only on the last one.

    Drop us a line if you need further assistance.

    Sincerely yours,
    Milen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. Rushikesh
    Rushikesh avatar
    3 posts
    Member since:
    Jun 2010

    Posted 23 Jul 2010 Link to this post

    Hi,
        I need sample application in silver-light that add sub-report-Item and report that link to sub-report in master report at code behind file of master.cs. (with 10 sub-report). when i get solution?

    thank you
    Rushikesh
  16. cheekl
    cheekl avatar
    55 posts
    Member since:
    Jul 2012

    Posted 29 Nov 2010 Link to this post

    I am using telerk reporting Q3 2010 to create a report with 4 subreport. Only the first subreport manage to show the result.
    The rest of the subreport encounter the following error.
    An error has occurred while processing TextBox 'TextBox1':
    The expression contains object 'ChannelDesc' that is not defined in the current context.


    Please help.

    Bellow is my code behind.

    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports Telerik.Reporting
    Imports Telerik.Reporting.Drawing

    Partial Public Class RptParentAprEnquiry
        Inherits Telerik.Reporting.Report

        Private _AprNo As String

        Public Sub New()
            InitializeComponent()
            Me.SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("DefaultDB").ConnectionString
        End Sub

        Public Sub setParamAPRNo(ByVal strAprNo As String)
            Try
                _AprNo = strAprNo
                Me.SqlDataSource1.Parameters.Item(0).Value = _AprNo
            Catch ex As Exception
            End Try
        End Sub

        Private Sub srAprBrand_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles srAprBrand.NeedDataSource
            Dim subrpt As Telerik.Reporting.Processing.SubReport = TryCast(sender, Telerik.Reporting.Processing.SubReport)
            subrpt.InnerReport.DataSource = GetDataSource("sp_tAprBrand_Sel#AprNo")
        End Sub

        Private Sub srAprChannel_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles srAprChannel.NeedDataSource
            Dim subrpt As Telerik.Reporting.Processing.SubReport = TryCast(sender, Telerik.Reporting.Processing.SubReport)
            subrpt.InnerReport.DataSource = GetDataSource("sp_tAprChannel_Sel#AprNo")
        End Sub

        Private Sub srAprWorkflow_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles srAprWorkflow.NeedDataSource
            Dim subrpt As Telerik.Reporting.Processing.SubReport = TryCast(sender, Telerik.Reporting.Processing.SubReport)
            subrpt.InnerReport.DataSource = GetDataSource("sp_tAprWorkflow_Sel#AprNo")
        End Sub

        Private Sub srAprDetail_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles srAprDetail.NeedDataSource
            Dim subrpt As Telerik.Reporting.Processing.SubReport = TryCast(sender, Telerik.Reporting.Processing.SubReport)
            subrpt.InnerReport.DataSource = GetDataSource("sp_tAprDetail_Sel#AprNo")
        End Sub

        Private Function GetDataSource(ByVal pstrSP As String) As SqlClient.SqlDataAdapter
            Dim strSP As String
            Try
                strSP = "exec " + pstrSP + " '" + _AprNo + "'"
                Dim adapter As New SqlClient.SqlDataAdapter(strSP, Me.SqlDataSource1.ConnectionString)
                Return adapter
            Catch ex As Exception
                Return Nothing
            End Try
        End Function

    End Class
  17. cheekl
    cheekl avatar
    55 posts
    Member since:
    Jul 2012

    Posted 29 Nov 2010 Link to this post

    i used SQL Server profiler to trace and notice that one the first subreport stored proc being executed. Why the rest of the stored proc is not executed eventhough the event needdatasource of all subreport are triggered.
  18. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 29 Nov 2010 Link to this post

    Hello cheekl,

    This is due to a problem that slipped into the Q3 release and has been immediately fixed in an internal build available for download from your account. Please download the internal build, upgrade and let us know if further help is needed.

    Sorry for the temporary inconvenience.

    All the best,
    Steve
    the Telerik team
    Get started with Telerik Reporting with numerous videos and detailed documentation.
  19. cheekl
    cheekl avatar
    55 posts
    Member since:
    Jul 2012

    Posted 30 Nov 2010 Link to this post

    The internal build solved by problem. Thanks
  20. Pavan kumar
    Pavan kumar avatar
    1 posts
    Member since:
    Jan 2012

    Posted 24 Jan 2012 Link to this post

    hi ,


    can i have a code sample with multiple subreports  with parameters .

    i.e i have a main report A and subreports B,C,D,E .

    how and where to assign the datasource  , paramets for the Subreports.

    also please give the flow of execution when sub reports are there in the report.

    every time only one report is working fine please help me. i am using the latest release (if need to install the internal build please give me link)
  21. Massimiliano Bassili
    Massimiliano Bassili avatar
    323 posts
    Member since:
    May 2006

    Posted 25 Jan 2012 Link to this post

    This topic explains it all: How-To: Creating Master-Detail Reports Using SubReports

    If the SubReports would display data that is not related to the master report data, then you do not need to do this.

    Cheers!
  22. Randa
    Randa avatar
    14 posts
    Member since:
    Jul 2011

    Posted 04 Apr 2012 Link to this post

    Is it possible to bound the data programmatically in the Subreport and in the main report?
    I need to do all the bounding programmatically .
    When I try this and assign the report source to subreport I get an error of :

    Object reference not set to an instance of an object.

    where do I set the datasource of the subreport programmatically ?
  23. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Apr 2012 Link to this post

    Hello Randa,

    The question is what do you mean by programmatically - do you create the entire report definition manually or you already have a report definition that you want to alter with code in events? Should you refer to the latter, then you can Use the NeedDataSource event to connect data. As explained in the Understanding Events, when you're in events, you should work with the processing counterpart of the report item.

    Kind regards,
    Steve
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
  24. waseem
    waseem avatar
    32 posts
    Member since:
    Jun 2006

    Posted 01 May 2013 Link to this post

    Dear Support Team.
    I have check the help for Master - Detail Report.
    http://www.telerik.com/help/reporting/designing-reports-master-detail.html
    its working fine if data source is given by wizard.

    if datasource is given from WinForms it not showing subreport data. only main report data is coming. My Question is how Main Report will interact with SubReport. is data source is defined in Forms Coding it self.

    Dim rptSub As New TravelReports.HotelSubReport

    objH.HotelID = itemHotel.Value

    rptSub.DataSource = objH.GetHotelByID

     

     

    Dim rpt As New TravelReports.HotelProductionReport

    rpt.Fromdate = DTPFrom.Value

    rpt.Todate = DTPTo.Value

    rpt.DataSource = ds

     

    Dim subreportinstance As New Telerik.Reporting.InstanceReportSource

    subreportinstance.ReportDocument = rptSub

     

     

     

    Dim instanceReportSource As New Telerik.Reporting.InstanceReportSource()

    instanceReportSource.ReportDocument = rpt

     

    ReportViewer1.ReportSource = instanceReportSource

    ReportViewer1.RefreshReport()

  25. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 02 May 2013 Link to this post

    Hello,

    Most likely you have to assign the subreportinstance to the ReportSource property of the SubReport item from the main report.
     
    Greetings,
    Chavdar
    the Telerik team

    Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

  26. waseem
    waseem avatar
    32 posts
    Member since:
    Jun 2006

    Posted 04 May 2013 Link to this post

    Dear
    please can you explain little bit more. I appreciate if you can give me just few lines of code.

    I just want to add result picture.
  27. Elian
    Admin
    Elian avatar
    435 posts

    Posted 08 May 2013 Link to this post

    Hi Muhammad,

    You are initializing the SubReport correctly, but you are not using it anywhere. You should get the subReport item from the master report and assign the rptSub as it's ReportSource:
    Dim subReportItem = DirectCast(rpt.Items.Find("subReport1", True)(0), Telerik.Reporting.SubReport)
    subReportItem.ReportSource = rptSub
     

    All the best,
    Elian
    the Telerik team

    Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

  28. waseem
    waseem avatar
    32 posts
    Member since:
    Jun 2006

    Posted 16 Aug 2013 Link to this post

    i give up :(
  29. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 21 Aug 2013 Link to this post

    Hi Muhammad,

    If you open a support thread and send us the problematic project we will be able to help you further with more accurate suggestions.

    Regards,
    Peter
    Telerik

    Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Back to Top
DevCraft banner