Article information
Article relates to
Telerik Reporting
Created by
Stef
Last modified
October 22, 2013
Last modified by
PROBLEM How to databind to collection properties of Business Objects
DESCRIPTION A common scenario is the need to set a data item’s DataSource property to a custom Business object. Depending on the underlying data-structure ObjectDataSource, OpenAccessDataSource or EntityDataSource components can be used to expose the properties of the Business object to the report. However, if the data schema is not flat and some of the properties represent child data collections. This presents the need of a way to bind a report to hierarchical data.
SOLUTION In order to be able to use hierarchical data you can take advantage of the Bindings functionality. Using it, you can bind declaratively the data item's DataSource property to a given collection property from your business object and the data item will display all collection items.
EXAMPLE Consider the following scenario illustrating a custom business object Contact having as a property a collection ofPhone objects. C#
public
class
Contact
{
string
Name {
get
;
set
; }
List<Phone> Phones {
}
Phone
Number {
Public
Class
Private
m_Name
As
String
Property
Name()
Get
Return
End
Set
(value
)
m_Name = value
m_Phones
List(Of Phone)
Phones()
List(Of Phone))
m_Phones = value
Number()
m_Number
m_Number = value
The Report.DataSource property is set to a collection of Contact objects and we want to display a list of Phone objects for each Contact object. For the purpose add a Table item and set its DataSource property to Fields.Phones via binding as illustrated on the image below.
For more information, see Bindings.
Note: The expressions are evaluated only during the report processing. Thus the data schema for the nested data item (Table) will not be available in the data explorer and in the wizards. You can use additional data source components bound to the nested business objects to help yourself with creating the report layout. Finally, apply the required bindings and remove the helper object data source components.
Resources Buy Try