Creating Alternating Colors for the Lines on a Report


To alternate color of the lines in the table, you can use the function RowNumber() .

To generate alternating colors for a table's Detail row, similar to those displayed in Table 13.7, you can set the BackgroundColor property of all columns and the table's Detail row to the expression =IIF((RowNumber("MyTable") Mod 2) = 0, "LightGrey", "White") .

Table 13.7. Alternating Table Row Colors

Row Number("MyTable")

Product Name

1

Adjustable Race

2

All-Purpose Bike Stand

3

AWC Logo Cap


What if alternating colors need to be set for the group header (or footer)? In this case, you can employ the RunningValue() function to return a row number of a group's header.

If you have a table with a single group that uses =Fields!ProductId.Value as a group expression and you only display the group's header in the result, you can set the BackgroundColor property for all columns in the group's header equal to the expression =IIF(RunningValue(Fields!Name.Value, CountDistinct, Nothing) Mod 2=0,"Gainsboro", "White") to generate alternating colors, similar to Table 13.8.

Table 13.8. Design of Alternating Colors for the Group Header

TH

Row Number (RunningValue)

Product Name

Items Sold

G1

=RunningValue(Fields!Name.Value, CountDistinct, Nothing)

=Fields!Name.Value

=RowNumber("G1")

THTable header row

G1Header of a single table group (named "G1") with the group expression =Fields!Name.Value


The resulting output is presented in Table 13.9. Note the number of items displayed in the Items Sold column. Although each group contains more than one hundred rowseach group's header is displayed only once, thus Items Sold displays aggregate number of rows in a group.

Table 13.9. Presentation of Alternating Colors for the Group Header/Footer

Row Number(RunningValue)

Product Name

Items Sold

1

Adjustable Race

1

2

All-Purpose Bike Stand

249

3

AWC Logo Cap

3382


Similarly to a single group, to display alternating colors when there is more than one table group, you can use RunningValue() on the combination of all group expressions, like this:

[View full width]
 
[View full width]
=RunningValue(CStr(Fields!ProductId.Value) & CStr(Fields!InnerGrouping.Value), CountDistinct, Nothing)

Note

The Demo Alternating Colors.rdl sample illustrates concepts discussed in this section.




Microsoft SQL Server 2005 Reporting Services
Microsoft SQL Server 2005 Reporting Services
ISBN: 0672327996
EAN: 2147483647
Year: 2004
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net