65.9K
CodeProject 正在变化。 阅读更多。
Home

SQL Reporting Services 技巧:页脚文本问题

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (3投票s)

2008年1月11日

CPOL

2分钟阅读

viewsIcon

34090

关于 ReportDesigner 页脚文本遇到问题的一个技巧。

引言

SQL Reporting Services中一个常见的问题是处理页脚,使其按照你想要的方式显示。报表设计器的页脚有很多限制。因此,为了使页脚按照你想要的方式显示,需要进行一些代码调整。我们将在本文中讨论这个问题以及解决方案。

背景

大多数人常用的方法是将页脚的RepeatOnNewPage属性设置为false。这将在第一页上显示页脚,但不会在所有页上显示。为了更清楚地说明,我们假设我的存储过程返回10条记录,并且我设计的报表使得每条记录跨越最多2页。当我将页脚的RepeatOnNewPage属性设置为false时,它只在第一条记录的第一页上显示页脚,而不在所有10条记录的第一页上显示。希望这能让你清楚地了解这个问题。

因此,迫切需要一个解决方案来解决这个问题。我们遇到了类似的问题,并在以下方式中找到了解决方案。我们在网上找到的一篇文章足以让我们摆脱这个问题。

该文章的链接是:http://blogs.msdn.com/ChrisHays/

在文章中,作者使用了报表服务的分组概念来隔离从数据库中来的记录,如果未这样做,所有记录将显示为单个报表。相同的概念,加上一些代码调整,将为我们解决这个问题。解决此问题的步骤如下。

使用代码

关于如何使用文章或代码的简要说明。类名、方法和属性,任何技巧或窍门。

代码块应设置为“Formatted”样式,如下所示

step 1 : 
 We have to take a textbox in the report which contains the group expression, i.e.., the field which we use to segregate the records 
 coming from the database.(for example, if you are grouping based on a field from database, say PatientID, then the textbox will 
 contain "=Fields!PatientID.Value" as expression.  Name the textbox as Category)

step 2 : 
 Add the following code to your Code section of the report. This code section is available 
 at  Report  --> Report Properties --> Code 

Shared offset as Integer
Shared currentgroup as Object

Public Function GetGroupPageNumber(group as Object, pagenumber as Integer) as Object
 If Not (group = currentgroup)
    offset = pagenumber - 1
    currentgroup = group
 End If
 Return pagenumber - offset
End Function


step 3 : 
   Use the following as visibility expression for the textbox in the page footer. 

    =Code.GetGroupPageNumber(ReportItems!Category.Value,Globals!PageNumber)


         


关注点

这段代码最重要的方面是,我们能够为报表设置页码,这将有助于很多情况下我们处理报表的页脚。

http://www.sakasolutions.com
© . All rights reserved.