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

Bind Report Controls to Data (Legacy Data Bindings)

  • 2 minutes to read

This topic describes how to bind report controls to data fields in the legacy data 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.Bindings, you can set a control’s bindable properties to the report’s data source fields.

The set of bindable properties differs depending on the control type. The Properties grid’s Data Bindings group provides access to these properties. Choose the property you want to bind and select the required data field in the drop-down list.

How to -  BindControl2DataField_1a

You can click the control’s smart tag and bind the most popular binding properties to data. Invoke the Data Binding option’s drop-down list and select the field.

How to -  BindControl2DataField_1

You can also specify the output values’ format using the XRBinding.FormatString property.

To unbind a control’s property, invoke the binding drop-down list and select None.

DataBinding - ReportControls4 (DesignUnBinding)

Bind Report Controls at Runtime

The XRControl.DataBindings collection stores all control bindings (XRBinding objects). You can bind a control to a data field at runtime by creating an XRBinding object with the appropriate settings and add it to the collection (for instance, using the XRBindingCollection.Add method).

The following code snippet illustrates how to bind a label control to the Categories table’s CategoryName data field:

using DevExpress.XtraReports.UI;
// ...

XRBinding binding = new XRBinding("Text", this.DataSource, "Categories.CategoryName", "Category: {0}");
xrLabel1.DataBindings.Add(binding);