问题描述
在SSRS中,是否可以从报告功能中引用报告变量?
In SSRS, is it possible to reference a report variable from a report function?
下面是我的报告功能.与其在函数中声明和设置MaxRFWIDRange,不如引用一个具有相同名称的报告变量.
Below is my report function. Instead of declaring and setting the MaxRFWIDRange in the function, I'd rather reference a report variable with the same name.
Function ValidateRFWIDRange(FromRFW As Integer, ToRFW As Integer) As Boolean
Dim DiffRFW As Integer
Dim MaxRFWIDRange As Integer
MaxRFWIDRange = 10000
DiffRFW = ToRFW - FromRFW
If DiffRFW > MaxRFWIDRange Then
Return False
Else
Return True
End if
End Function
推荐答案
您似乎可以做到这一点.
It looks like you can do this.
我通过在报表中添加变量 TestVariable
,然后添加以下自定义代码来进行测试:
I tested this by adding a variable TestVariable
to a report, then adding the following custom code:
Function TestVariableFunctionality(var as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable) As String
Return var.Value
End Function
我从文本框中调用了函数,如下所示:
I called the function from a textbox like so:
= Code.TestVariableFunctionality(变量!TestVariable)
这将在文本框中将变量的值输出为字符串.
This outputs the variable's value in the textbox as a string.
您必须将完整的名称空间声明为 Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable
,因为未单独定义 Variable
.有关更多信息,请参见下文.
You must declare the full namespace as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable
, because Variable
alone is not defined. See below for more info.
您需要的只是一段自定义代码.
All you need is a piece of custom code.
公共函数SetVariableValue(val为Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable)
Public Function SetVariableValue(val as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable)
val.Value = val.Value + 2
val.Value = val.Value + 2
结束功能
就这么简单.我在该函数中所做的只是获取报告变量引用,将2加到现有值上.就是这样.
As simple as that. All i'm doing in the function is, take the report variable reference, add 2 to the existing value. That's it.
如何从报告项中调用此功能?
How you can call this function from your report item?
= Code.SetVariableValue(变量!Reportvariable1)
=Code.SetVariableValue(Variables!Reportvariable1)
这将起到神奇作用.另外请注意,在上面的表达式中,我只是传递变量引用而不是其值.
This will do the magic. Also note that in the above expression i'm just passing the variable reference and not its value.
这篇关于报告功能中的SSRS参考报告变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!