Conditionally Change a Label's Text
- 2 minutes to read
This tutorial demonstrates how you can use a calculated field to conditionally change a label's text in a report.
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:
Do the following to conditionally change a label's text:
- 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.
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.
Finally, drop the required data fields (and the created calculated field as well) from the Field List on the report's Detail band.