的报表正文中显示页码

的报表正文中显示页码

本文介绍了如何在 SSRS 2008 R2 的报表正文中显示页码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为很多开发者都面临着尝试使用 SSRS 2008 R2 来显示页码的问题.

有一个替代解决方案需要 SSRS 2010 + 版本.否则你会一直得到 1.

There is an alternative solution which requires SSRS 2010 + version. Otherwise you will get 1 all the time.

转到报告" -> 报告属性" -> 代码"

Custom Code 部分,输入以下内容:

In the Custom Code section, enter the following:

Public Function PageNumber() as String
     Dim str as String
     str = Me.Report.Globals!PageNumber.ToString()
     Return str
End Function

Public Function TotalPages() as String
     Dim str as String
     str = Me.Report.Globals!TotalPages.ToString()
     Return str
End Function

现在您可以在报告的任何位置(页眉、正文或页脚)访问这些功能.因此,要在位于正文的文本框中输出页码和总页数,只需输入以下值:

Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:

="Page " + Code.PageNumber() + " of " + Code.TotalPages()

解决方案不适用于 SSRS 2008 R2.

This solution DOES NOT work with SSRS 2008 R2.

但是有一个解决方法,它适用于任何高于 2008 R2(包括 2008 R2)的版本.我将发布作为答案,希望它可以帮助一些在这个问题上挣扎的人.

However there is a workaround, it will work with any version higher than 2008 R2 (include 2008 R2). I will post as an answer, hope it will help some people whoever struggling with this issue.

推荐答案

首先需要用到报表变量:在report空白处右击->变量->创建PageCount等变量(设置默认值为0)

First you need to use report variables:right click on the empty space of report -> Variables -> Create a variable such as PageCount (set default value to 0)

然后在页眉或页脚 -> 创建一个文本框并设置表达式 ->

Then in you header or footer -> create a textbox and set expression ->

=Variables!PageCount.SetValue(Variables!PageCount.Value+1)

每页会自动增加.(重要提示:不要从页眉或页脚隐藏它,如果隐藏框,SetValue 将不起作用,因此将字体更改为 1 或将文本更改为白色,执行任何操作,只是不要隐藏它(它会在设置发生时打印True"))

It will automatically increase for each page.(IMPORTANT: DO NOT hide it from header or footer, the SetValue WON'T work if you hide the box, so change the font to 1 or text to white, do whatever, just DO NOT hide it (it will print 'True' as the setting took places))

然后你可以使用:

=Variables!PageCount.Value

在报告正文的任何​​部分访问页码.

at any part of your report body to access the page number.

重要提示:请注意,我尝试使用 Globals!PageNumber 来设置变量,但最终无法从报表正文访问它.因此,它必须是可从页眉/页脚或正文访问的内容.

IMPORTANT: Please NOTE that I tried to use Globals!PageNumber to set the variable but ends up it was NOT accessible from report body. So, it has to be something both accessible from Header/Footer OR Body.

就我而言,我必须为我的组的每个实例重置页码.所以我只是在组的末尾设置了一个触发器.(例如,我检查是否有我的 Total 值返回,因为我知道对于我的组的每一端我都会有一个 Total 显示.

In my case, I have to reset the Page number per each instance of my Group.So I just set a trigger at the end of the group.(e.g. I check if I have my Total value returns, because i know for each end of my group i will have a Total display.

因为在函数IIF中,True和False部分都会被处理,所以如果你把setter放在IIF中,如下所示:

Because of in function IIF both True and False part will be processed, so if you put setters in IIF such as below:

=IIF(IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(Variables!PageCount.Value+1),Variables!PageCount.SetValue(0))

 )

您将始终获得值 0,因为报告将检查 True 部分然后是 False 部分,两个设置器都将被执行(值将设置两次)

you will ends up have value 0 all the time, because the report will Check the True Part then the False part, both setters will be executed (value will be set twice)

所以我们需要 2 个盒子和类似的东西:(你必须隐藏不必要的框你的检查条件)

so we need 2 boxes and something like:(You have to hide unnecessary box your checking conditions)

=IIF(IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(Variables!PageCount.Value+1),"")
)

NOT IsNothing(ReportItems!TotalBox.Value)

=IIF(NOT IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(0),"")
)

同样,当 IsNothing(ReportItems!TotalBox.Value)

当然,您可以使用其他方式来确定组实例的结束,例如:在组表的末尾制作一个仅包含固定值的文本框.并隐藏它.当您检查触发器时,只需执行与我类似的方法即可.

Of course you could use some other way to determine the end of a group instance, like:make a textbox which ONLY contains a fixed value at the end of your group table. and hide it. when you checking the trigger just do the similar approach as I do.

它适用于 2008 R2 以上的所有版本(包括在内).

It works fine for all versions above 2008 R2 (included).

这篇关于如何在 SSRS 2008 R2 的报表正文中显示页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:59