Telerik Reporting

Report Definition

The Report Definition is created during the first stage of the life cycle. This is the actual .NET class that represents the report. It is always a subclass Telerik.Reporting.Report and contains information about report items and their properties. Report items are represented by the private fields of the report class.

Let's illustrate this with an example. While in design-time, if you add a TextBox to the Detail Section of the report that you are designing, a private field of type TextBox will be added to the code-behind file and some basic initialization code will be generated within the InitalizeComponent method of the report class.

Note

The InitializeComponentmethod initializes (creates) a Report and its child items.It is a special method recognized and parsed by the Report Designer in order to display the report in design-time.

This object will later serve as the definition for creating a concrete instance of the TextBox for each row form the data source. These definition objects are of the types that reside in the Telerik.Reporting namespace, for example Telerik.Reporting.TextBox.

Report Processing

The second stage of the report life cycle involves combining the report definition with the data source. The processing engine performs all grouping, sorting and filtering calculations and iterates over all rows from the data source and creates the appropriate processing items based on the item definitions created earlier and the actual data. Based on the original item definition (Telerik.Reporting.TextBox for example) and the actual data in the current data row a new item is created. This item is known as a processing item (Telerik.Reporting.Processing.TextBox for example) and bears all characteristics of its definition item, but it is bound to the respective data field from the current data row. While the definition TextBox's Value property may contain something like "=Fields.FirstName", the processing item's Text property will be equal to "John".

The Processing Engine provides the developer with a way to intervene in this process. Just before the processing item is bound to data, the ItemDataBinding event of its definition item is raised. After the processing item has been data bound the ItemDataBound event is raised. By subscribing a listener for those events, the developer can modify the default behavior at run-time. The sender parameter of the event handler methods is in fact the processing report item.

Let us demonstrate this with a simple example. Suppose that we have a TextBox containing the job position of an employee. Assume that the TextBox's Value property equals "=Fields.JobPosition", where JobPosition is a column from the data source containing values like "Team Leader", "Senior Developer", "Junior Developer", "Quality Assurance", etc. For the sake of our example, suppose that we would like to color all developers in Blue.

First we need to attach to the TextBox's ItemDataBound event.

Note

Double-click the event in the property grid and an event handler method will be automatically generated for you.

CopyC#
//…
this.textBox1.ItemDataBound += newSystem.EventHandler(this.textBox1_ItemDataBound);
//…
private void textBox1_ItemDataBound(object sender,System.EventArgs e)
{
}
//…
CopyVB.NET
'...
Private Sub textBox1_ItemDataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textBox1.ItemDataBound
End Sub
'...

As we mentioned earlier the sender argument is in fact the processing TextBox that has already been data bound. Its Text property will hold the job position of the current employee. The method will be called for each data row, i.e. for each employee we have in the data source. So the only thing we have left to do is cast the sender, check the position, and do the coloring if needed:

CopyC#
private void textBox1_ItemDataBound(object sender,System.EventArgs e)
{
   Telerik.Reporting.Processing.TextBox txtPosition =(Telerik.Reporting.Processing.TextBox)sender;
   if(txtPosition.Text.Contains("Developer"))
   {
      txtPosition.Style.BackgroundColor = Color.Blue;
   }
}
CopyVB.NET
Private Sub textBox1_ItemDataBound(ByVal sender As Object, ByVal e As EventArgs) 
   Dim txtPosition As Telerik.Reporting.Processing.TextBox = DirectCast(sender, Telerik.Reporting.Processing.TextBox) 
   If txtPosition.Text.Contains("Developer") Then 
      txtPosition.Style.BackgroundColor = Color.Blue 
   End If 
End Sub
Note

Be very careful when working inside event handlers.  If by mistake you modify the reporting item (the private field of the report class, i.e. this.textBox1) instead of its processing counterpart (the sender argument), all subsequent processing items will be modeled after the modified reporting item.

Report Rendering

After processing is over, the processed report is ready for rendering in one of the many available formats.

See Also

Other Resources