Glossary Item Box

Getting Started | Walkthrough: Calculated Fields

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Adding Field Expressions

In ActiveReports, C# expressions can be used in the DataField property to specify textbox output in a report, such as date/time, mathematical calculations or conditional values. Any field expression should begin with the equals (=) sign.

Using Field Expressions

To use a mathematical expression

Change the DataField property for the text box to the mathematical calculation desired.

Examples: =UnitPrice+5

                =Quantity-5

                =Quantity*UnitPrice

                =UnitPrice/QuantityPerUnit

To use a substring

Change the DataField property for the text box to the substring needed. If setting up grouping, change the GroupHeader's DataField property to the same substring.

Example: =ProductName.Substring(0, 1)

To use date/time

Change the DataField property for the text box to the following.

Example: =System.DateTime.Now.ToString()

To create a conditional value

Change the DataField property for the text box to the conditional statement desired.

Example: =(UnitsInStock > 0)?"In Stock":"Backorder"

To concatenate fields

Change the DataField property for the text box to the following.

Examples: ="There are " + UnitsInStock + " units of " + ProductName + " in stock."

                =TitleOfCourtesy + " " + FirstName + " " + LastName

NOTE: ActiveReports for .NET 2.0 automatically handles null values, replacing them with an empty string.

To round a calculation

Change the DataField Property for the text box to the following.

Example: =(double)System.Math.Round(UnitPrice*UnitsOnOrder,2)

To use modular division

Change the DataField Property for the text box to the following to get the remainder (2 in this case).

Example: =22%(5)

To replace a null value

Change the DataField Property for the text box to the following to replace nulls with your own value.

=(Region == System.DBNull.Value) ? "No region specified" : Region

Getting Started | Walkthrough: Calculated Fields

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.