This is a migrated thread and some comments may be shown as answers.

Sub Reports

27 Answers 2542 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bhaskar
Top achievements
Rank 1
Bhaskar asked on 19 Dec 2007, 07:34 PM
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

27 Answers, 1 is accepted

Sort by
0
Milen | Product Manager @DX
Telerik team
answered on 20 Dec 2007, 04:22 PM
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
0
Bhaskar
Top achievements
Rank 1
answered on 26 Dec 2007, 11:57 AM
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.
0
Rossen Hristov
Telerik team
answered on 27 Dec 2007, 07:49 AM
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
0
Madu
Top achievements
Rank 1
answered on 21 Jan 2008, 02:17 PM
hi,
can you please tell me how should i use a subreport inside a master report.
and bind its data.

regards,
madu
0
Milen | Product Manager @DX
Telerik team
answered on 22 Jan 2008, 08:52 AM
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
0
Adam
Top achievements
Rank 1
answered on 28 Apr 2008, 05:28 PM
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?
0
Chavdar
Telerik team
answered on 29 Apr 2008, 08:57 AM
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
0
Adam
Top achievements
Rank 1
answered on 29 Apr 2008, 01:45 PM
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.
0
Maveric
Top achievements
Rank 2
answered on 29 Sep 2008, 03:56 PM
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
0
Milen | Product Manager @DX
Telerik team
answered on 30 Sep 2008, 09:21 AM
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.
0
Maveric
Top achievements
Rank 2
answered on 02 Oct 2008, 01:43 PM
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 

0
Milen | Product Manager @DX
Telerik team
answered on 02 Oct 2008, 02:51 PM
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.
0
Rushikesh
Top achievements
Rank 1
answered on 23 Jul 2010, 07:29 AM
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
0
cheekl
Top achievements
Rank 2
answered on 29 Nov 2010, 09:57 AM
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
0
cheekl
Top achievements
Rank 2
answered on 29 Nov 2010, 10:25 AM
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.
0
Steve
Telerik team
answered on 29 Nov 2010, 05:36 PM
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.
0
cheekl
Top achievements
Rank 2
answered on 01 Dec 2010, 04:14 AM
The internal build solved by problem. Thanks
0
Pavan kumar
Top achievements
Rank 1
answered on 25 Jan 2012, 04:57 AM
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)
0
Massimiliano Bassili
Top achievements
Rank 1
answered on 25 Jan 2012, 11:06 AM
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!
0
Randa
Top achievements
Rank 1
answered on 05 Apr 2012, 12:06 AM
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 ?
0
Steve
Telerik team
answered on 06 Apr 2012, 08:02 AM
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.
0
waseem
Top achievements
Rank 2
answered on 01 May 2013, 08:38 AM
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()

0
Chavdar
Telerik team
answered on 02 May 2013, 09:14 AM
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.

0
waseem
Top achievements
Rank 2
answered on 04 May 2013, 07:53 AM
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.
0
Elian
Telerik team
answered on 08 May 2013, 12:08 PM
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.

0
waseem
Top achievements
Rank 2
answered on 16 Aug 2013, 10:43 AM
i give up :(
0
Peter
Telerik team
answered on 21 Aug 2013, 07:14 AM
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.

Tags
General Discussions
Asked by
Bhaskar
Top achievements
Rank 1
Answers by
Milen | Product Manager @DX
Telerik team
Bhaskar
Top achievements
Rank 1
Rossen Hristov
Telerik team
Madu
Top achievements
Rank 1
Adam
Top achievements
Rank 1
Chavdar
Telerik team
Maveric
Top achievements
Rank 2
Rushikesh
Top achievements
Rank 1
cheekl
Top achievements
Rank 2
Steve
Telerik team
Pavan kumar
Top achievements
Rank 1
Massimiliano Bassili
Top achievements
Rank 1
Randa
Top achievements
Rank 1
waseem
Top achievements
Rank 2
Elian
Telerik team
Peter
Telerik team
Share this question
or