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

Binding a SubReport to a Property of an instance

2 Answers 143 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Will
Top achievements
Rank 1
Will asked on 04 Jun 2015, 12:00 PM

Hi guys, 

I know this has been asked in different ways before but what I'm looking to do is dynamically assign a reports datasource at runtime. Within this report will be a subreport, generated for every record of the datasource.

So my example would be by having a absence report for employees. The parent report will be bound to a list of employee object, in which there will a list of absences of type absences. This list is what I want to bind to a sub report. (see code below)

I've been going through a couple of other similar question on here and trying to figure out the best way.  

What I have is a sub report with the bindings 

Property Path                        Expression

DataSource                            =ReportItem.Absences

I found the documentation a little unclear in what is the datasource is and what is the properties being displayed. So any and all help is greatly appreciated.

 

public Class Employee{
public string EmployeeName {get; set;}
public string EmployeeNumber {get; set;}
public List<Absence> Absences {get; set;}
}
 
public Class Absence{
public DateTime AbsenceDateFrom{get;set;}
public DateTime AbsenceDateTo{get;set;}
public string AbsenceReason{get;set;}
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 04 Jun 2015, 12:09 PM
Hello Will,

You can bind the sub-report's data source to the ReportItem.DataObject to get the current employee data as the data source for the sub-report, or bind the data source to the ReportItem.DataObject.Absences to get the current employee's absences list as the data source for the sub-report.

The differences and specifics of both approaches are explained in the How to use the ReportItem.DataObject property in expressions help article.

Regards,
Nasko
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
Will
Top achievements
Rank 1
answered on 04 Jun 2015, 01:13 PM

Hi Nasko, 

Thanks for the reply and link. However using the third method (from the link) results in the sub report displaying 

"An error has occurred while processing Subreport:

The expression contains object 'Absences' that is not defined in the current context."

The other methods talk about using sql datasources, but this data is in memory and can't be purged with SQL Statements?

Thanks

Will

Tags
General Discussions
Asked by
Will
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Will
Top achievements
Rank 1
Share this question
or