New to Telerik Reporting? Download free 30-day trial

Using the Events of the Sections

The various report Section objects expose these events:

Event Description
ItemDataBinding Fires just before the item is bound to data.
ItemDataBound Fires just after the item is bound to data.

In ItemDataBinding and ItemDataBound events use the "sender" argument of the event handler to get a reference to the section object. From the section object you can reference any of the items the section contains, i.e. TextBoxes, PictureBoxes, etc. You can also use the section DataObject property to access the data fields for the section.

Be aware that the "sender" section object is of type Telerik.Reporting.Processing.ReportItemBase, not the definition item Telerik.Reporting.ReportItemBase.

The example below demonstrates getting a reference to the detail section of the report and finding a specific TextBox within the section. The example also shows retrieving data source column values for the section and using it to alter the TextBox.

private void detail_ItemDataBinding(object sender, EventArgs e)
{
    Telerik.Reporting.Processing.DetailSection section = (sender as Telerik.Reporting.Processing.DetailSection);
    Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "textBox1");
    object title = section.DataObject["Title"];
    if ((string)title == "Developer")
    {
        txt.Style.BackgroundColor = System.Drawing.Color.Blue;
    }
}
Private Sub detail_ItemDataBinding(sender As Object, e As EventArgs)
    Dim section As Telerik.Reporting.Processing.DetailSection = TryCast(sender, Telerik.Reporting.Processing.DetailSection)
    Dim txt As Telerik.Reporting.Processing.TextBox = DirectCast(Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "textBox1"), Telerik.Reporting.Processing.TextBox)
    Dim title As Object = section.DataObject("Title")
    If DirectCast(title, String) = "Developer" Then
        txt.Style.BackgroundColor = System.Drawing.Color.Blue
    End If
End Sub

The second example demonstrates getting a reference to the detail section of the report, finding all its children and setting a BackgroundColor to them:

void DetailSection_ItemDataBinding_Using_ILayoutElementContainer_Children(object sender, EventArgs e)
{
    Processing.DetailSection processingInstance = (Processing.DetailSection)sender;
    Processing.ILayoutElementContainer processingContainer = processingInstance as Processing.ILayoutElementContainer;
    if (null != processingContainer)
    {
        foreach (Processing.LayoutElement processingChild in processingContainer.Children)
        {
            Processing.VisualElement visualChild = processingChild as Processing.VisualElement;
            if (null != visualChild)
            {
                visualChild.Style.BackgroundColor = System.Drawing.Color.Blue;
            }
        }
    }
}
Private Sub DetailSection_ItemDataBinding_Using_ILayoutElementContainer_Children(sender As Object, e As EventArgs)
    Dim processingInstance As Processing.DetailSection = DirectCast(sender, Processing.DetailSection)
    Dim processingContainer As Processing.ILayoutElementContainer = TryCast(processingInstance, Processing.ILayoutElementContainer)
    If processingContainer IsNot Nothing Then
        For Each processingChild As Processing.LayoutElement In processingContainer.Children
            Dim visualChild As Processing.VisualElement = TryCast(processingChild, Processing.VisualElement)
            If visualChild IsNot Nothing Then
                visualChild.Style.BackgroundColor = System.Drawing.Color.Blue
            End If
        Next
    End If
End Sub
In this article