Nested Subreport Background Color - SSRS 2005

by Rich Rousseau 19. December 2008 07:18

I was recently styling a SQL Server Reporting Services 2005 report that contained a subreport as one of its columns.  This was a tabular report that needed an alternating background color for each row.  The trouble with this is that the subreport cell doesn't expose a BackgroundColor property in the report designer. 

 

No BackgroundColor Property!

 

 

For my first attempt at fixing this, I created a parameter on the subreport called BGColor and setup the subreport's text box BackgroundColor property to get its value from the parameter.  

 


Setting the Subreport BackgroundColor via Parameter.


This worked fine as long as the cell containing the subreport remains its original size.  However my report had columns that sometimes displayed more than one line of text, which caused the row height to expand by a few lines.  This expanded the cell around the subreport, but the subreport did not expand to fill this new area.

 

Bad Report!

 

 

At this point I decided it didn't make sense that the cell containing the subreport didn't have a BackgroundColor property.  A quick search for the RDL schema showed that it's legal to have a BackgroundColor element in the Style element of a subreport element.  Armed with this new information, I opened the RDL file in Notepad2 and added the following…

 

                    <Subreport Name="subreport1">
                      <ReportName>SubReport</ReportName>
                      <Style>
                        <BackgroundColor>=iif(RowNumber(Nothing) Mod 2, "Gray", "White")</BackgroundColor>
                        <BorderStyle>
                          <Default>Solid</Default>
                        </BorderStyle>
                      </Style>
                      <ZIndex>1</ZIndex>
                    </Subreport>

 

 

The BackgroundColor of the subreport will now fill the entire cell even when the cell is expanded. 


Note: The visual studio report designer will not display the background color.  You'll need to deploy the report to an actual Report Server to see the full background color.

 

 

Good Report!


 

Comments

3/31/2009 11:45:30 AM #

Cam Schwieder

Great post Rich. It is the only one of it's kind that I could find to help me with this problem when I encountered it. Unfortunatly I am using ssrs 2008 and this solution doesn't appear to work anymore.

Thankfully I did find out a different way that does work in ssrs 2008. I modified the rdl so that the sub report item was contained within a Rectangle inside the cell, and then set the background color of the rectangle. I have a quick example below if it'll help. Hopefully this will save someone else from having this problem!!

Cam

<CellContents>
  <Subreport Name="Subreport3">
....
  </Subreport>
</CellContents>


Became

<CellContents>
  <Rectangle Name="Rectangle1">
    <ReportItems>
      <Subreport Name="Subreport3">
....
      </Subreport>
    </ReportItems>
    <Style>
      <BackgroundColor>=iif(RowNumber(Nothing) Mod 2, "Gray", "White")</BackgroundColor>
    </Style>
  </Rectangle>
</CellContents>

Cam Schwieder Canada |