Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternate row colours with grouping in RDLC

Tags:

rdlc

report

I need to create alternate row colours in my RDLC report which also takes into account groups.

If I use the expression

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

Obviously this creates problems when groups are used. I've not had much luck finding information so any help would be great.

like image 511
nik0lai Avatar asked Dec 10 '10 15:12

nik0lai


People also ask

How do I change the row color in Rdlc?

Open the dropdown, and you'll see all the colors, but also a menu item at the bottom called Expression. When you select that item, a dialog box will open that allows you to insert an expression to determine the background color for that row.

How to give alternate colors to rows in SSRS?

Right-click the data row as shown in the below screenshot, click F4 or properties window in the View menu. When selecting this, you will see the BackgroundColor option. By default, it is No Color, which means that there is no color for the background and use can select any colors.

How do I create a group in Rdlc report?

To open the Report Builder, select “Layout” From the “View” menu. Provide the fields in the dataset in a table by right-clicking ->insert -> table. To create a group, on the left side of the screen, right-click and choose Add Group ->Row Group ->Parent Group. Choose the required option for grouping.


3 Answers

Decided to go with the following code I found online:

=IIf(RunningValue(Fields!GroupId.Value, CountDistinct, Nothing) MOD 2, "White", "#d6f1fc")

It doesnt alternate every row colour but keeps all the rows in that group the same colour which make the report nice and easy to read.

like image 175
nik0lai Avatar answered Oct 18 '22 22:10

nik0lai


I know this topic was brought up ages ago, but in case somebody has a similar issue (like I did) and runs into this thread, here is how I tackled it. Here is an example of the report grouping and sample results in my report:

Group 1
   Sub 1
   Sub 2
   Sub 3

Group 2
   Sub 1
   Sub 2
   Sub 3

Notice that 'Sub [1-3]' are the exact same header. When using (Fields!GroupId.Value, CountDistinct, Nothing), the statement determines that there are only 3 unique values, and when it gets to the repeating subgroups (Sub [1-3]), the result of the RunningValue does not increase.

You can test this out by putting an extra column in your report and then the expression: (RunningValue(Fields!GroupId.Value, CountDistinct, Nothing). The results would look like this:

Group 1
   Sub 1   1
   Sub 2   2
   Sub 3   3

Group 2
   Sub 1   3
   Sub 2   3
   Sub 3   3

Because the values start repeating, the 'mod 2' portion of the alternating row logic gets messed up. To work around this I had the RunningValue statement combine the Group header as well as the Sub group:

(RunningValue(Fields!GroupId.Value+Fields!SubGroupId.Value, CountDistinct, Nothing)

After I did this I got this result:

Group 1
   Sub 1   1
   Sub 2   2
   Sub 3   3

Group 2
   Sub 1   4
   Sub 2   5
   Sub 3   6

Throw that in to your alternating row expression and it should work!

like image 29
Russ Avatar answered Oct 18 '22 22:10

Russ


use this: =iif(RowNumber(Nothing) Mod 2 = 0, true,false)

like image 33
AbhishekS Avatar answered Oct 18 '22 22:10

AbhishekS