简体   繁体   English

如何使用表达式在 SSRS 中设置文本框的可见性?

[英]How do I set the visibility of a text box in SSRS using an expression?

I have a subtotal field for a calculated column that I want to hide when my report has not ran yet because on days with no data it shows up as NaN on the report.我有一个计算列的小计字段,我想在我的报告尚未运行时隐藏它,因为在没有数据的日子里,它在报告中显示为NaN

I have tried two methods but neither are working and I am sure it is almost correct.我尝试了两种方法,但都没有奏效,我相信它几乎是正确的。 I just don't know what is wrong with the expression.我只是不知道表达式有什么问题。

I tried hiding if my dataset had no rows.如果我的数据集没有行,我尝试隐藏。

=IIf((CountRows("ScannerStatisticsData")=0),False,True)

I also tried making a calculation我也试着做一个计算

=iif((fields!Scans.Value / fields!numberOfCases.Value) = 0, False, True)

I also tried checking isnothing on one of the columns in the calculation我还尝试在计算中的一列上检查 isnothing

=iif(IsNothing(fields!Scans.Value), False, True)

What am I doing wrong?我究竟做错了什么?

I tried the example that you have provided and the only difference is that you have True and False values switched as @bdparrish had pointed out.我尝试了您提供的示例,唯一的区别是您切换了 True 和 False 值,正如@bdparrish指出的那样。 Here is a working example of making an SSRS Texbox visible or hidden based on the number of rows present in a dataset.这是一个根据数据集中存在的行数使 SSRS Texbox 可见或隐藏的工作示例。 This example uses SSRS 2008 R2 .此示例使用SSRS 2008 R2

Step-by-step process: SSRS 2008 R2分步过程: SSRS 2008 R2

  1. In this example, the report has a dataset named Items and has textbox to show row counts.在此示例中,报表有一个名为Items的数据集,并有一个显示行数的文本框。 It also has another textbox which will be visible only if the dataset Items has rows.它还有另一个文本框,仅当数据集 Items 有行时才可见。

  2. Right-click on the textbox that should be visible/hidden based on an expression and select Text Box Properties... .右键单击应该基于表达式可见/隐藏的文本框和 select Text Box Properties... Refer screenshot # 1 .请参阅屏幕截图# 1

  3. On the Text Box Properties dialog, click on Visibility from the left section.在“ Text Box Properties对话框中,单击左侧部分的“ Visibility ”。 Refer screenshot # 2 .参考截图# 2

  4. Select Show or hide based on an epxression . Select Show or hide based on an epxression

  5. Click on the expression button fx .单击表达式按钮fx

  6. Enter the expression =IIf(CountRows("Items") = 0, True, False) .输入表达式=IIf(CountRows("Items") = 0, True, False) Note that this expression is to hide the Textbox ( Hidden ).请注意,此表达式是隐藏文本框(隐藏)。

  7. Click OK twice to close the dialogs.单击确定两次关闭对话框。

  8. Screenshot # 3 shows data in the SQL Server table dbo.Items , which is the source for the report data set Items .屏幕截图# 3显示了 SQL 服务器表dbo.Items中的数据,它是报告数据集Items的源。 The table contains 3 rows .该表包含3 行 Screenshot # 4 shows the sample report execution against the data.屏幕截图 # 4显示了针对数据执行的示例报告。

  9. Screenshot # 5 shows data in the SQL Server table dbo.Items , which is the source for the report data set Items .屏幕截图 # 5显示 SQL 服务器表dbo.Items中的数据,它是报告数据集Items的源。 The table contains no data .该表不包含任何数据 Screenshot # 6 shows the sample report execution against the data.屏幕截图 # 6显示了针对数据执行的示例报告。

Hope that helps.希望有帮助。

Screenshot #1:截图#1:

1

Screenshot #2:截图#2:

2

Screenshot #3:截图#3:

3

Screenshot #4:截图#4:

4

Screenshot #5:截图#5:

5

Screenshot #6:截图#6:

6

=IIf((CountRows("ScannerStatisticsData")=0),False,True)

Should be replaced with应该替换为

=IIf((CountRows("ScannerStatisticsData")=0),True,False)

because the Visibility expression set up the Hidden value.因为可见性表达式设置了隐藏值。

This didn't work这没有用

=IIf((CountRows("ScannerStatisticsData") = 0),False,True)

but this did and I can't really explain why但这确实如此,我无法解释为什么

=IIf((CountRows("ScannerStatisticsData") < 1),False,True)

guess SSRS doesn't like equal comparisons as much as less than.猜测 SSRS 不喜欢相等的比较。

instead of this而不是这个

=IIf((CountRows("ScannerStatisticsData")=0),False,True)

write only the expression when you want to hide当你想隐藏时只写表达式

CountRows("ScannerStatisticsData")=0

or change the order of true and false places as below或更改真假位置的顺序如下

=IIf((CountRows("ScannerStatisticsData")=0),True,False)

because the Visibility expression set up the Hidden value.因为可见性表达式设置了隐藏值。 that you can find above the text area as您可以在文本区域上方找到

" Set expression for: Hidden " 

Visibility of the text box depends on the Hidden Value文本框的可见性取决于隐藏值

As per the below example, if the internal condition satisfies then text box Hidden functionality will be True else if the condition fails then text box Hidden functionality will be False根据下面的示例,如果内部条件满足,则文本框隐藏功能将为真,否则如果条件失败,则文本框隐藏功能将为假

=IIf((CountRows("ScannerStatisticsData") = 0), True, False)

Twood, Visibility expression is the expressions you write on how you want the "visibility" to behave. Twood,可见性表达式是您编写的关于您希望“可见性”如何表现的表达式。 So, if you would want to hide or show the textbox, you want to write this:所以,如果你想隐藏或显示文本框,你想这样写:

=IIf((CountRows("ScannerStatisticsData")=0),True,False)

This means, if the dataset is 0, you want to hide the textbox.这意味着,如果数据集为 0,则您要隐藏文本框。

the rdl file content: rdl文件内容:

<Visibility><Hidden>=Parameters!casetype.Value=300</Hidden></Visibility>

so the text box will hidden, if your expression is true.因此,如果您的表达式为真,文本框将隐藏。

Switch your false and true returns?切换你的虚假和真实回报? I think if you put those as a function in the visibility area, then false will show it and true will not show it.我认为如果您将它们作为 function 放在可见区域中,那么 false 会显示它,而 true 不会显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM