You can embed expressions within the text of Label elements and the values of ReportParameter objects by enclosing the expression in square brackets. The following example shows the text of a label with a function call expression embedded within it:
Example Copy Code |
---|
The date and time now is: [Now()] |
The expression will be evaluated when the report, containing the label is processed by a call to its Run method. Once the expression is evaluated, its string representation is inserted at its place in the text. In the above example, when the label is displayed, the result will be similar to the following: "The date and time now is: 12/15/2000 1:05:11 PM".
By default the result from the evaluation of an embedded expression is formatted to a string through a call to its ToString method. It is also possible to apply custom formatting as illustrated by the following example:
Example Copy Code |
---|
The date and time now is: [Now() @ "d"] |
The above example will format the date received as a result of the expression evaluation using short date format. The result will be similar to the following: "The date and time now is: 12/15/2000".
Generally, you can apply any string, which would be a valid format string for the ToString method of the expression evaluation result. The following example illustrates how you can apply formatting to an expression, which evaluates to a number. The example assumes that Price is a field of type double in the data source related to the current context.
Example Copy Code |
---|
Cost: [Price @ "$#,##0.00"] |
When applying formatting to an expression, the current culture is used by default. The following example will produce text similar to "16 Jan" when evaluated on machines with regional settings set to en-US or similar:
Example Copy Code |
---|
[Now() @ "dd MMM"] |
Evaluating the example is dependent on the current culture however and may yield unexpected results if the current culture is not the one we expect. To force explicitly specify the culture, use the following syntax:
Example Copy Code |
---|
[Now() @ "dd MMM" : "en-US"] |
This will force the expression to always be evaluated with the specified culture regardless of the current regional settings.
The built-in expression editor facilitates the creation of expressions for both labels and report parameters in design-time. To open the editor, press the '...' button next to the Text property (or Value property in the case of parameters) of the label in the property grid. The following image illustrates the Expression Editor:
The editor contains the following sections: the expression text editor at the top, and the list of categories, items, as well as information panel at the bottom.
The text editor is the place to enter the text of the expression by typing. This editor supports auto-completion and function information. To activate auto-completion, press CTRL+Space. To display the information about the function in the current context, press CTRL+SHIFT+Space.
This tree view contains the categories of the various elements that can be included in an expression. The categories include Keywords, Report parameters, Table fields, Operators, and Common functions. The functions and operators are further divided to subcategories based on their type. For functions these include Date & Time, Math, Text, and more. The operators include arithmetic, logical, comparison, and more.
This view displays all expression elements contained in the currently selected category in the Category View. Selecting an item will display additional information about this item and its usage in the Info View to the right. Double-clicking on an item will automatically insert the item at the current position in the Text Editor.
This view displays information about the currently selected item in the Item View as well as syntax and example usage (if available).