Udostępnij za pośrednictwem


Adding Style and Formatting to a Report (Visual Studio Report Designer)

You can set properties to control the appearance of items on a report. Properties can be static or set to an expression that evaluates to a specific value. You can also set formatting properties on a text box to specify numbers and dates are presented.

Note

Locale settings on the report or text box affect the formatting options that are available. To specify the locale at the report level, set the Language property for the report in the Properties window. For more information about specifying locale on a text box, see Adding Text Boxes to a Report (Visual Studio Report Designer).

Setting Style Properties on Report Items

Each report item has style properties that control the appearance of the item. These properties include border style, color, font style, and padding. Some styles are not available to all report items. For example, font style properties apply only to a text box or subtotal, because only those items can contain text. You can apply the same border style and padding properties to all sides of a report item, or you can apply different styles to each side of the item.

You apply a style property to an item by selecting the item and editing the properties for the item in the Properties window.

Applying Conditional Formatting

You can design a report so that different styles are applied to items based on the data in the report. For example, negative numbers in a report can be displayed in red.

To make styles dynamic, use an expression instead of a static value for the style properties of the item. For example, to make a text box return a negative value in red for the field Profit, use the following expression in the Color property of the text box:

=iif(Fields!Profit.Value < 0, "Red", "Black")

Creating a Green-Bar Report

To apply a green-bar effect (alternating colors every other row) to a table in a report, use the following expression in the BackgroundColor property of each text box in the detail row:

=iif(RowNumber(Nothing) Mod 2, "PaleGreen", "White")

You can build expressions based on a number of functions. For more information, see Using Expressions in a Report (Visual Studio Report Designer).

Formatting Numbers and Dates

You can specify a format for numeric and date values by updating the Format property of its text box with a formatting string. For example, you can set a text box for a numeric field to display the number as currency. Reporting Services uses Microsoft .NET Framework formatting strings or you can create a custom formatting string for the Format property.

Note

To apply formatting to a text box, the text box must contain an expression, for example, =Fields!LineTotal.Value or =1000. If the text box is not an expression, that is, if the text in the text box does not begin with the equal (=) sign, then the text is interpreted as a string and formatting does not apply.

Formatting Numbers

The following table lists common .NET Framework number formatting strings.

Format string Name

C or c

Currency

D or d

Decimal

E or e

Scientific

F or f

Fixed-point

G or g

General

N or n

Number

P or p

Percentage

R or r

Round-trip

X or x

Hexadecimal

You can modify many of the format strings to include a precision specifier that defines the number of digits to the right of the decimal point. For example, a formatting string of D0 formats the number so that it has no digits after the decimal point. You can also use custom formatting strings, for example, #,###.

Formatting Dates

The following table lists common .NET Framework date formatting strings.

Format string Name

d

Short date

D

Long date

t

Short time

T

Long time

f

Full date/time (short time)

F

Full date/time (long time)

g

General date/time (short time)

G

General date/time (long time)

M or m

Month day

R or r

RFC1123 pattern

Y or y

Year month

You can also a use custom formatting strings; for example, dd/MM/yy. For more information about .NET Framework formatting strings, see Formatting Types.

See Also

Concepts

Defining a Report Layout (Visual Studio Report Designer)