The requested page is not available for the requested platform. You are viewing the content for Default platform.

Conditionally Change a Label's Text

  • 2 min to read

This tutorial demonstrates how you can use a calculated field to conditionally change a label's text in a report.

Note

This approach to conditionally changing a label's text applies when the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Bindings.

See Conditionally Change a Label's Text to learn about the alternative approach to conditionally changing a label's text without using calculated fields.

See Data Binding Modes to learn more about the available binding modes.

The report created in this tutorial displays a custom text when the number of ordered units equals zero:

How to - ConditionallyFormatLabelText_2

Do the following to conditionally change a label's text:

  1. To create a table report in this tutorial, start with a report that is bound to the "CategoryProducts" view of the sample Northwind database (the nwind.mdb file included with the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports.
  2. To create a calculated field, right-click any of the data fields in the Field List,, and in the invoked menu, click Add Calculated Field.

    HowTo - CreateCalcField_0

  3. Next, in the Property Grid, set the CalculatedField.FieldType property to String. Then locate the CalculatedField.Expression property and click its ellipsis button. The Expression Editor will appear.

    How to - ConditionallyFormatLabelText_0

    In this dialog, define the required condition for the calculated field (e.g., Iif([UnitsOnOrder] == 0, 'None', [UnitsOnOrder]). This expression means that if the UnitsOnOrder data field's value is equal to 0, the control's text will be set to None; otherwise, it will display the UnitsOnOrder field's value).

    To close the dialog, click OK.

  4. Finally, drop the required data fields (and the created calculated field as well) from the Field List on the report's Detail band.

    How to - ConditionallyFormatLabelText_1