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

DataSource binding for SubReport

6 Answers 838 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alexey
Top achievements
Rank 1
Alexey asked on 17 Jan 2012, 12:27 AM
Hi,

I have the subreport inside a list and I want to send items from the list's data source to this subreport. I added binding ReportSource.DataSource=Field.Group to my subreport and put this subreport into a panel inside the list. 

What's my next step? How can I access this data (Field.Group) within my subreport and display it?

Regards,
Alex.

6 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 19 Jan 2012, 02:15 PM
Hi,

If the binding is successful, then inside the sub-report you use the fields as normal. Fields.FieldName. If for example your group has properties: GroupName and GroupNumber, then you can call them by Fields.GruopName and Fields.GroupNumber.

For reference I have attached a sample project showing the usage of sub-reports and data-binding. 

All the best,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Tomas
Top achievements
Rank 1
answered on 06 Aug 2012, 09:38 AM
Hi Elian,

How can I accomplish the datasouce binding using Q2 2012?
Because this clearly doesn't work anymore:
this.subReport1.Bindings.Add(new Telerik.Reporting.Binding("ReportSource.DataSource", "=ReportItem.DataObject.Departments"));

Tomas
0
Elian
Telerik team
answered on 07 Aug 2012, 08:28 AM
Hello Tomas,

Since the introduction of the new Report Sources things have changed a bit. 
In your case, one option to get the same result would be to move the binding from the main report, to the detailed report. Since the sub-report is a child of the main report it can access it's elements (including the data-elements).  For example this binding placed in the detailed report, would have the same output.
this.Bindings.Add(new Telerik.Reporting.Binding("DataSource", "=ReportItem.Parent.DataObject.Departments"));
You can also create a user function that will assign the ReportSource to the SubReport item. 

public static ReportSource GetReportSource(object dataObject)
{
    var report = new DetailedReport();
    report.DataSource = dataObject;
    return new InstanceReportSource { ReportDocument = report };
}
and the binding in the main report will be:
this.subReport1.Bindings.Add(new Telerik.Reporting.Binding("ReportSource", "= GetReportSource(ReportItem.DataObject)"));
 
Regards,
Elian
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Tomas
Top achievements
Rank 1
answered on 08 Aug 2012, 05:46 AM
Thank you Ellan. My reports works as expected again.

Tomas
0
Karl Wilkens
Top achievements
Rank 1
answered on 06 Jan 2013, 04:22 PM
Hi,

REALLY struggling with this and having spent a day reading various posts, links to dead non functioning help pages and the like, conclude your documentation is very weak on the subject.

In CodeBehind in the master report we have a sub report and want to assign it to a data table that is part of a 3 table set. I have sub reports setup for each table, and corresponding NeedDataSource handlers in the main report code behind, but only the first NeedDataSource fires. 

I read somewhere that if the goal is to have multiple sub reports, then each part of the report needs to have its own NeedsdataSource. Unfortunately, only the main report's NeedDataSource event fires. The sub report NeedDataSource events never fire.

ANY help appreciated. Judging by all the posts, this is an area that needs some work.
0
Steve
Telerik team
answered on 08 Jan 2013, 09:12 PM
Hi Karl,

As documented here (Using the NeedDataSource event to connect data) NeedDataSource of a Data Item (SubReport in your case) is only fired if it still has no data source attached. Have you double checked that the reports that you specify as SubReports do not have DataSource property set?

Regards,
Steve
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Tags
General Discussions
Asked by
Alexey
Top achievements
Rank 1
Answers by
Elian
Telerik team
Tomas
Top achievements
Rank 1
Karl Wilkens
Top achievements
Rank 1
Steve
Telerik team
Share this question
or