Feeds:
Posts
Comments

Posts Tagged ‘Embeding Code In Reporting Services’

Reporting Services gives us a number of functions to use in a report. For example, we have functions to sum and average numbers, and functions to count values. Visual Basic functions such as InStr and DateAdd are also supported, as are Iif and Switch. However, embedded code allows you to implement functions with custom code.

Custom code comes in two forms. We can write a custom assembly and reference the assembly from a report. This is approach is preferred when you need to share code across a number of reports, or to decouple calculations and rules from a report into a class library and possibly share the class library with other applications. A custom assembly is also a good choice when you need additional security permissions.

The second form of custom code is code embedded directly into a report. Let’s say depending on the value of a field, we will want to adjust the color from a plain black to a bright red. With a report in the designer we will go to the Report menu and select Report Properties. In the dialog box (shown below), we can enter code into the text area.

To use the code, we can select a textbox (or any control with a Color property that we want to set programmatically) and open the properties toolbox window. In this case, we will set the Font Color property for a Textbox control in a report table. We can enter the following expression, which assumes we have a query returning a Quantity column:

=Code.SetColor(Fields!Quantity.Value)

One of the nice features of Reporting Services is the ability to use an expression instead of a hard value on any property. When the report renders, this expression will change the colors of the font depending on the value in each row. Again, you can use expressions on any property to control layout, colors, and styles.

Read Full Post »