Skip to main content
A newer version of this page is available. .

Bind Report Controls to Data (Expression Bindings)

  • 3 minutes to read

This topic describes how to bind report controls to data fields in the expression bindings mode.

Bind Report Controls at Design Time

After connecting a report to data, the Field List panel displays the data source’s hierarchy and provides access to the available data fields. This panel allows you to bind report controls to data in all binding modes.

Dropping a data field onto a report’s surface creates a new report control bound to the corresponding field.

DesignTimeFeatures - FieldList2.png

Dropping a data field onto an existing control binds this control to the corresponding field.

DesignTimeFeatures - FieldList3.png

See the Field List document for more information about using this panel for data binding.

Note that while binding, the field is assigned to the control’s property with the DefaultBindableProperty attribute (usually, XRControl.Text).

You can also bind a control to the calculated fields and report parameters, and combine static and dynamic content in the same control (for instance, to append a text prefix or postfix to a value obtained from a database).

When the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Expressions or DataBindingMode.ExpressionsAdvanced, a report uses expressions to provide data to controls. In these modes, the Properties grid contains the Expressions tab. This tab provides properties that you can specify using expressions with available data fields.

You can also access expressions for the most popular properties using the control’s smart tag. Clicking the property’s ellipsis button invokes the Expression Editor in which you can specify the required data field or construct a complex binding expression involving two or more data fields.

label-expression-editor-complex-binding

You do not need to run the Expression Editor if you want to bind a report control to a single data field. Click the control’s smart tag, invoke the Expression‘s drop-down list and select the required field.

label-smart-tag-expression-drop-down

After you bind the report control to data, you can format the control’s values using the Format String option (the XRControl.TextFormatString property).

You can also use a binding expression to shape report data (for instance, calculate summary results or conditionally format data). See the Shape Data (Expression Bindings) documentation section for more information.

Bind Report Controls at Runtime

The XRControl.ExpressionBindings property provides access to the control’s expression bindings. An ExpressionBinding object implements each expression binding’s functionality and contains the following settings:

You can specify a report control’s binding expression at runtime by creating an ExpressionBinding object with the required settings and adding it to the XRControl.ExpressionBindings collection. The following code snippet demonstrates how to specify a custom expression for a label’s XRControl.Text property.

using DevExpress.XtraReports.UI;

public XtraReport1() {
    // ...
    ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]*[UnitsInStock]");
    xrLabel1.ExpressionBindings.Add(expressionBinding);
}
See Also