Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Problem of Empty Pages in SSRS

0.00/5 (No votes)
18 Aug 2015CPOL2 min read 6.8K  
The main problem of this issue is the width of the report page and the margins. Many articles are written on that. Please check if your problem is this before continuing this article. Else check the solution provided for empty pages problem.

Introduction

The main cause of this issue is the width of the report page and the margins. Many articles are written on that. Please check if your problem is that before continuing this article.

I faced the problem of empty pages and discovered that it was because of a field in the tablix that has cangrow property set to true. This field will create empty pages if its size is inside a specific range of lines that is approximately equal to the size of the page.

So for example, if this field holds between 30 to 40 lines of text, empty pages will appear in the report.

Options to resolve this problem:

  1. Set cangrow property to false. This is a restricting option. So if your text is more than 30 lines, only 30 lines will appear.
  2. Add empty lines by code to your text so that it grows out of the problematic range. Check code below:

Using the code

VB
Sub SaveHowManyEmptyLinesToAddToDescription()
        Dim description As String = CurrentEntity.Fields("MC_RCMANALY_COMMENTS_T").Value.ToString()
        Dim numberOfLines As Double = GetNumberOfLinesInText(212, description)
        Dim numberOfRequiredLines As Integer = GetNumberOfRequiredLines(Convert.ToInt32(numberOfLines), 43, 51, 44)
        CurrentEntity.Fields("MC_RCMANALY_NO_OF_REQUI_LINES_TO_ADD_CHR").Value = numberOfRequiredLines.ToString
End Sub

In the function above, I:

  1. get the field that is creating the problem (description).
  2. get the number of lines this field will make in the report. The function GetNumberOfLinesInText will do this by taking the text and the number of chars in a line.
  3. use GetNumberOfRequiredLines to get the number of lines I should add to go out of the problematic range

    This function will take the number of lines of my text, the upper and lower boundaries of the range, and how many lines a page can hold (this is used in case the text grows for more than 1 page).

  4. Finally, save my result in another field
VB
Function GetNumberOfLinesInText(ByVal CharsPerLine As Double, ByVal Text As String) As Double
        Dim totalNumberOfLines As Double = 0
        Dim x As String() = Text.Split(vbLf)
        totalNumberOfLines = x.Length
        For Each paragraph As String In x
            Dim parLines As Double = paragraph.Length / CharsPerLine
            Dim parlinesCeiled As Double = Math.Ceiling(parLines)
            If parlinesCeiled > 0 Then
                totalNumberOfLines += (parlinesCeiled - 1)
            End If
        Next
        Return totalNumberOfLines
End Function
 
Function GetNumberOfRequiredLines(ByVal numberOfTextLines As Integer, ByVal lowerRange As Integer, ByVal upperRange As Integer, ByVal linesPerPage As Integer) As Integer
        For x As Integer = 0 To 10
            If numberOfTextLines < upperRange + x * linesPerPage And numberOfTextLines > lowerRange + x * linesPerPage Then
                Return (upperRange + x * linesPerPage) - numberOfTextLines
            End If
        Next
        Return 0
End Function

After saving the value of the required number of empty lines I need to add, I pass this value to the report.

Then in the report, you set the property of spaceAfter to the expression below:

=CINT(FIELDS!NameOfField.Value)*8 & "pt"

note: I multiplied by 8 is because the font size is 8.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)