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

Nested SubReport binding

17 Answers 272 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 13 Dec 2014, 06:16 AM
I want to know how to bind a subreport from another subreport from a master report.I have a main report which is a main order which in its detail section there is a subreport of categories which in its detail section there is a fee subreport. This last one is that I'm trying to use as generic control. But I don't know how to bind this control.

Main Report
+ Header
 + Detail Section
   + Categories Sub Report
   + Header
   + Details Section
      + Fee Sub Report
      + Header
      + Detail section
      + Footer
   + Footer
+ Footer

e.g.

Master report
-------------
Category 1
Fee 1 $10
Fee 2 $5
Fee 3 $15
Category 2
Fee 2 $5
Fee 3 $15
Category 3
Fee 4 $50

In my main report (MasterReport) I have in the constructor a LoadData method, after InitializeComponents, that initializes the subreport like this

List<Categories> categories = GetCategories();
CategorySubReport subReport = new CategorySubReport(true);
InstanceReportSource source = new InstanceReportSource();
source.ReportDocument = subReport;
this.catSubReport.ReportSource = source;

Which works well because it lists my categories. But then in the ItemDataBound of the Category Sub Report, I tried to do the same thing for the fee sub report. But the only thing that I got, it's the first list of fees of the category 1 but linked to the last category and the previous categories from the list don't display the fee control.

e.g.

Master report
-------------
Category 1
Category 2
Category 3
Fee 1 $10
Fee 2 $5
Fee 3 $15

Category ItemDataBound from Detail Section

**details_ItemDataBound **

 Telerik.Reporting.Processing.DetailSection detailSection = (Telerik.Reporting.Processing.DetailSection)sender;
Category cat = detailSection.DataObject.RawData as Category;

Telerik.Reporting.SubReport feeSubReport = (Telerik.Reporting.SubReport)detailSection.ItemDefinition.Items.Find("FeeSubReport", false)[0];
Telerik.Reporting.InstanceReportSource source = new Telerik.Reporting.InstanceReportSource();
source.ReportDocument = new FeeSubReport(cat.Fees);
feeSubReport.ReportSource = source;


**FeeSubReport class**

public partial class FeeSubReport : Telerik.Reporting.Report
{
public FeeSubReport(List<Fee> fees)
{
InitializeComponent();
this.DataSource = fees;
}
}

I read that I need to use the NeedDataSource event of the FeeSubReport. So in my CategorySubReport where is placed the FeeSubReport I implemented the NeedDataSource event but it never gets called or triggered. (I don't have a datasource liked to the SubReport) and I don't what exactly to solve this.Before of using this approach, everything was excellent with the Telerik's table control which was bound with the fee collection but I realized that I was using fee tables in many reports duplicating code ...so that's why I decided to create a subreport of fee that I can initialize and reuse but this will be used in many subreport and not in a main report.

17 Answers, 1 is accepted

Sort by
0
KS
Top achievements
Rank 1
answered on 13 Dec 2014, 09:42 AM
Hi,

All these events are unnecessary. See How to bind the DataSource of a SubReport in the designer.

-KS
0
Luis
Top achievements
Rank 1
answered on 14 Dec 2014, 12:52 AM
But I still don't get it. Can you explain this with an example please? I'm really new to this Telerik Reporting components for one week and I stuck with this. I tried what you wrote using also this url as reference: http://www.telerik.com/help/reporting/expressions-bindings.html

I went to subreport and then in Edit Bindings I added DataSource property and as a Expression = ReportItem.DataObject or Parent.DataObject ...... but I don't still get it. I went to the designer class and code generated was this. this.Bindings.Add(new Telerik.Reporting.Binding("DataSource", "ReportItem.Parent.DataObject"));

But as I said my FeeSubReport needs a List<Fee> collection that can belongs to many objects. 

My DataObject can be Categories (Category.Fees) or can be another object that can have the property collection. e.g. Order.Fees.  How can the designer know the type of my object. I tried at least with the designer as the example from the page that you suggested but nothing happens.

Thanks in advance.
0
Hinata
Top achievements
Rank 1
answered on 17 Dec 2014, 03:35 PM
Hi Luis,

The designer won't know the type of your object and won't display its data fields. You just write them manually and it works.
The approach is described in this article: http://www.telerik.com/help/reporting/data-items-how-to-use-data-object.html
If it seems a little too complex to do it with a subreport you can always try with a nested table first.
0
KS
Top achievements
Rank 1
answered on 17 Dec 2014, 03:52 PM
 Hi,

I see. When you are in the sub report the designer does not know about the master report and its data. Check the fields name and type it manually in the sub report.

-KS
0
Luis
Top achievements
Rank 1
answered on 22 Dec 2014, 08:48 PM
Thank you guys for your answers. I used a Table control temporarily the last week. But I took again this subject at work in a new development cycle and I found this article that finally help me to use my custom subreport.

Hope this can help anyone else.

Thanks.

http://sylnsr.blogspot.ca/2012/07/passing-variables-to-subreports-in.html
0
Bhavika
Top achievements
Rank 1
answered on 10 Jul 2017, 07:44 PM

Hello,

Can I used Nested Sub Report?

e.g.

Master Report - MainReport which contains Sub Report - SubReport1 and that Sub Report - SubReport1 also contain Sub Report - DetailSubReport1.

Is it Possible? Please suggest me.

Thanks & Regards,

Bhavika

 

 

     

0
Stef
Telerik team
answered on 11 Jul 2017, 09:38 AM
Hello Bhavika,

With regards to our discussion in Make section fill page, you can use nested Sub reports in order to produce the designed layout by adding a GroupFooterSection|ReportFooterSection with PrintAtBottom set to true in each, and proper borders of the used SubReport items (not the content of the sub report, but its container) to draw lines.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bhavika
Top achievements
Rank 1
answered on 11 Jul 2017, 12:21 PM
ok..Thank you Stef.
0
Bhavika
Top achievements
Rank 1
answered on 11 Jul 2017, 08:02 PM

Hi Stef,

I am not using this scenario in Make section fill page.

I am using this in different report.

e.g.
Master Report - MainReport which contains Sub Report - SubReport1 and that Sub Report - SubReport1 also contain Sub Report - SubSubReport11.

SubReport1 has multiple data - e.g. Product 1,Product 2 etc.

SubSubReport11 has multiple data - e.g. Product 1 details, Product 2 details etc.

How can I bind data source for SubSubReport11 to get data for each product?

Please give me any idea.

Thanks & Regards,

Bhavika

 

 

0
Bhavika
Top achievements
Rank 1
answered on 12 Jul 2017, 08:02 PM
Any update for this?
0
Stef
Telerik team
answered on 13 Jul 2017, 04:28 PM
Hello Bhavika,

If the data is available on the upper level report, you can use the approach from How to bind Sub Report to Main Report's Data. The sub report can use a binding to the data object of its container (parent report) via expression.

If the data is not available in the parent report, you can use the approach with passing information to sub reports via their report parameters - How to: Create a Master-Detail Report Using a SubReport Item. Each report has its own data source, where data is filtered via report parameters. Report parameters of each sub report are mapped to fields/expressions/parameters of the parent report.

On a side note, if it is an emergency, please submit a support ticket as we cannot guarantee a response by Telerik representative in a timely manner in forums.


Thank you for your understanding.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bhavika
Top achievements
Rank 1
answered on 13 Jul 2017, 05:13 PM

Hello Stef,

Thanks for your reply.

Yes, It is an emergency.

I used c# programming to bind data source and passing parameter.

I am able to display data in SubSubReport11.

But It always display last product details for each product. that is the problem.

So my question is How can I bind details for SubSubReport11 for each product?

I am passing parameter 'ProductId' to SubSubReport11 , so I can get details for each product.

But still it always binds last product's details. I don't know why ?

Please help me and give me solution.

Thanks & Regards,

Bhavika

0
Bhavika
Top achievements
Rank 1
answered on 13 Jul 2017, 07:41 PM
Hello,
I used c# programming to bind data source and passing parameter.
I am able to display data in SubSubReport11.
But It always display last product details for each product. that is the problem.
So my question is How can I bind details for SubSubReport11 for each product?
I am passing parameter 'ProductId' to SubSubReport11 , so I can get details for each product.
But still it always binds last product's details. I don't know why ?
Please help me and give me solution.
Thanks & Regards,
Bhavika
0
Bhavika
Top achievements
Rank 1
answered on 17 Jul 2017, 03:15 PM
Any update for this?
0
Stef
Telerik team
answered on 18 Jul 2017, 01:01 PM
Hi Bhavika,

Please design reports to have report parameters, and map sub reports' parameters to fields of the main report - step 7 from Configure SubReport. If you are modifying the SubReport item's ReportSource property at run-time, copy the SubReport.ReportSource.Parameters collection in the newly created Reportsource object's Parameters collection. This will include the mapping between the sub report's parameters and fields of the parent report via expressions. Then you will not set an exact hard-coded value to all produced sub reports:
var mainReport = new MainReport();
 
Telerik.Reporting.SubReport sr = (Telerik.Reporting.SubReport)mainReport.Report.Items.Find("SubReport1", true)(0);
var typeName  = (sr.ReportSource as TypeReportSource).TypeName;//or cast to the type of the used ReportSource
var subreport = (Report)Activator.CreateInstance(Type.GetType(typeName))
 
//modify the sub report instance
subreport.DataSource = tblFS;
//or if it is a nested Table item use the Find method
//Dim table As Telerik.Reporting.Table = DirectCast(subreport.Items.Find("Table1",True)(0),Telerik.Reporting.Table)
//table.DataSource = tblFS
 
//update the SubReport item's ReportSource to display the modified report
InstanceReportSource IRS = new InstanceReportSource();
IRS.ReportDocument = subreport;
//move original parameters settings to the new ReportSource object
IRS.Parameters.AddRange(sr.ReportSource.Parameters);
 
sr.ReportSource = IRS;



In order to provide you more accurate suggestions we will need to check the settings of the original reports and the code where they are modified and bound to new data objects.

If it is an emergency, please submit a ticket through the support ticketing system. We try to monitor forums, but we cannot guarantee a response in a timely manner by a Telerik representative here.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bhavika
Top achievements
Rank 1
answered on 18 Jul 2017, 03:24 PM

Thank you stef.

I have applied your code. but I got error.

My code is just below:

        var POsReport = new POsReport ();

        var purchaseorders = salesOrder.PurchaseOrders.OrderBy(x => x.Number).ToList();
        POsReport.DataSource = purchaseorders;    // this is main report and contains multiple data
       

            for (int i = 0; i < purchaseorders.Count; i++)
            {
             
                var poLines = purchaseorders[i].PurchaseOrderLines.OrderBy(x => x.LineNumber);  // get details of particular item using 'for' loop

                Telerik.Reporting.SubReport sr = (Telerik.Reporting.SubReport)POsReport.Report.Items.Find("POLines", true)(0);  // got error 'Method name expected'.
                var typeName = (sr.ReportSource as TypeReportSource).TypeName;
                var subreport = (Report)Activator.CreateInstance(Type.GetType(typeName));

                subreport.DataSource = poLines;
               
                InstanceReportSource IRS = new InstanceReportSource();
                IRS.ReportDocument = subreport;
                //move original parameters settings to the new ReportSource object
                IRS.Parameters.AddRange(sr.ReportSource.Parameters);

                sr.ReportSource = IRS;

            }

 

Please give me solution.

0
Praveen
Top achievements
Rank 1
answered on 13 Dec 2017, 11:02 AM
Hi could anyone plzz give me a solution for this....I have a telerik report, in that page a table contains some values and if the values in the table increases then they are appearing on the next header of the page(i.e the values are merging on to the next section)...
Tags
General Discussions
Asked by
Luis
Top achievements
Rank 1
Answers by
KS
Top achievements
Rank 1
Luis
Top achievements
Rank 1
Hinata
Top achievements
Rank 1
Bhavika
Top achievements
Rank 1
Stef
Telerik team
Praveen
Top achievements
Rank 1
Share this question
or