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

Master-SubReport: how to get master row's data for subreport?

4 Answers 104 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yanli
Top achievements
Rank 1
Yanli asked on 06 Aug 2013, 08:20 AM
I'm passing data sets for my master and subreport. For each row in master report, the subreport needs to call a procedure using the master row data. 

I added NeedDataSource handler in the master report constructor:
subReport2.NeedDataSource += new EventHandler(subReport2_NeedDataSource);

then I added NeedDataSource handler function as below:

private void subReport2_NeedDataSource(object sender, EventArgs e)
{
    //read parent/master row data:
    int goalID = ??; //how to get the data from the current master row?
 
    //get measurements for this goal:
    System.Data.DataSet ds2 = DataHelper.Measurements_GetMeasurementsForGoal(goalID);
    var objectDataSource = new ObjectDataSource();
    objectDataSource.DataSource = ds2;
    subReport2.Report.DataSource = objectDataSource;
}

 I have GoalID as a field of master report. How to get the current master row to read the goalID? the sender object in subReport2_NeedDataSource is an instance of SubReport2. 

your help is very appreciated!

4 Answers, 1 is accepted

Sort by
0
Squall
Top achievements
Rank 1
answered on 06 Aug 2013, 01:59 PM
You can try this:

private void subReport2_NeedDataSource(object sender, EventArgs e)
{
 
     var procSubreport = (Telerik.Reporting.Processing.ReportItemBase)sender;
 
     object goalID = procSubreport.Report.DataObject["GoalID"];
 
}

or just add ObjectDataSource for the subreport report datasource and pass the field as Subreport report parameter.
http://www.telerik.com/help/reporting/objectdatasource.html
http://www.telerik.com/help/reporting/designing-reports-master-detail.html

0
Yanli
Top achievements
Rank 1
answered on 06 Aug 2013, 03:50 PM
I got NullReferenceException when trying to access procSubreport.Report.DataObject

in the NeedDataSource event handler, the subreport doesn't have any data source bound to it yet. Is it possible to access parent report data item here? 
0
Accepted
Stef
Telerik team
answered on 09 Aug 2013, 01:03 PM
Hi Yanli,

The current value of the GoalID field can be obtained from the processing item's DataObject, e.g: procSubreport.DataObject["GoalID"]

The other approach is to pass the field as value for a parameter in the sub report definition. For more details take a look at the How to: Create a Master-Detail Report Using a SubReport Item help article.

Both options are illustrated in the attached sample project.

I hope this helps you.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Yanli
Top achievements
Rank 1
answered on 09 Aug 2013, 09:50 PM
thanks for the reply. I figured it out.
Tags
General Discussions
Asked by
Yanli
Top achievements
Rank 1
Answers by
Squall
Top achievements
Rank 1
Yanli
Top achievements
Rank 1
Stef
Telerik team
Share this question
or