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

SubReport DataSource Help

1 Answer 136 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
christine
Top achievements
Rank 1
christine asked on 03 Dec 2012, 11:52 PM
I have just upgraded a reporting project that is several years old and I see that there have been some breaking changes in the reporting structure.  

I several sub reports inside of a report.  The datasource to each one is determined dynamically inside of the Ctor of the report itself.
How would I accomplish this within the new model?   Any help would be greatly appreciated. 


public ClaimsReport()
        {
            InitializeComponent();

            BindToSubReport(1, subReport_Sacramento);
            BindToSubReport(2, subReport_Modesto);
            BindToSubReport(3, subReport_Fresno);
        }

    public  void BindToSubReport(int officeID, SubReport subReport)
        {
            using (eEntities context = new eEntities ()) {

                List<StrapReportClaimOutput> outputList = context.StrapReportClaimOutputs
                                                 .Where(x => x.OfficeID.Equals(officeID))
                                                 .OrderByDescending(o => o.TotalDocketing)
                                                 .ToList();

               subReport.ReportSource.DataSource = outputList;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 06 Dec 2012, 04:49 PM
Hello Christine,

You should now create an InstanceReportSource and assign the report to its ReportDocument property. For more information refer to the following links:

As for setting DataSource for a SubReport item, the easiest way would be to use Binding for the detailed report. Since the sub-report is a child of the main report it can access it's elements (including the data-elements) e.g.:

Copy Code
this.Bindings.Add(new Telerik.Reporting.Binding("DataSource", "=ReportItem.Parent.DataObject.ColumnUsedForDS"));

You can also create a user function that will assign the ReportSource to the SubReport item. 

Copy Code
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:
Copy Code
this.subReport1.Bindings.Add(new Telerik.Reporting.Binding("ReportSource", "= GetReportSource(ReportItem.DataObject)"));

Kind regards,
Steve
the Telerik team

HAPPY WITH TELERIK 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
christine
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or