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
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
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
can you please tell me how should i use a subreport inside a master report.
and bind its data.
regards,
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
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
Thanks for the quick response as usual.
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
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.
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 |
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.
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
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
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
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)
If the SubReports would display data that is not related to the master report data, then you do not need to do this.
Cheers!
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 ?
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
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()
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.
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.
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.
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.