Expressions are preceded by an "=" sign, which tells the report-processing engine that the statement following this sign has to be evaluated. It is certainly possible to turn even a constant to an expression. For example, the VerticalAlign property can have constant values: Top , Middle , and Bottom , or, alternatively, a developer can express those constants as expressions ="Top" , ="Middle" , or ="Bottom" . If you are more familiar with Microsoft Excel than VB.NET, expressions are similar to VBA expressions in Excel. Starting an expression with an "=" sign only increases the resemblance. Expressions can be used to achieve several goals: display the values on a report and calculate values for style and formatting properties. Style change can include variation of colors, highlights, and shapes of displayed data. To accomplish those goals, expressions are used in properties of reporting items. Most properties of the reporting items support expressions, and few (such as Name ) do not. Most of the expressions in properties are strings, few are VBA constants, such as true or False , and a few have numeric values. Let's start our examination by taking a look at a simple yet common expression: =Fields!FirstName.Value This is a common expression for retrieving values from a data set. As expected, the expression starts with an equal sign. Next is the keyword " Fields ." This is in reference to the Fields collection of the parent data set. The next piece ( !FirstName.Value ) makes reference to the FirstName field in the Fields collections, and gets its value. It is also possible to use functions around fields to achieve a desired result. For example: =Sum(Fields!Price.Value) Expressions can contain one or more of the following:
Tip If you use an expression for the value of a property and you either receive an error or are not able to achieve the desired result (for example, text alignment does not work properly), you need to make sure that the type of the expression value is appropriate for the property. For example, if you use the following expression for the VerticalAlign property =IIF(1=1, Top, Bottom) , SSRS returns a runtime error: The VerticalAlign expression for the text box '<textbox name>' contains an error: [BC30451] Name 'Top' is not declared. The proper expression is: =IIF(1=1,"Top","Bottom") . Alternatively, if you enter =IIF(1=1,10,0) in the BorderWidth property, there is no runtime error, and SSRS is not going to provide an expected width, because the property expects a string ( "10pt" ) as opposed to a numeric value. |