【发布时间】:2017-08-10 23:20:22
【问题描述】:
我只研究了 rdlc 表达式值中可能的 2 个,就像
=iif((Fields!Gender.Value="1"),"Male","Female")
在这里我只能使用 2 种可能性。但如果我想检查 3 个或更多条件,我该怎么做?
【问题讨论】:
-
能否请您标记正确答案以帮助其他人找到解决方案?
标签: reportviewer rdlc iif-function
我只研究了 rdlc 表达式值中可能的 2 个,就像
=iif((Fields!Gender.Value="1"),"Male","Female")
在这里我只能使用 2 种可能性。但如果我想检查 3 个或更多条件,我该怎么做?
【问题讨论】:
标签: reportviewer rdlc iif-function
如果你有更多的条件,使用 Switch,它也更具可读性。
=Switch(
Fields!Gender.Value = 1, "Male",
Fields!Gender.Value = 2, "Female"
)
【讨论】:
您可以使用报告的Code 属性。右键单击报告外的空白处并单击 Report Properties 或单击报告菜单并单击报告属性。
单击“代码”选项卡并输入您的条件检查语句,如下所示
Public Function GetGender(ByVal val as String) As String
Dim retVal as String = ""
If(val = "1")
retVal = "Male"
Else If (val = "2")
retVal = "???"
Else If (val = "3")
retVal = "???"
Else
retVal = "???"
End If
Return retVal
End Function
然后在你的文本框表达式中调用函数
= Code.GetGender(Fields!Gender.Value)
【讨论】:
IIf在表达式框中的一行?这很难调试,但也很有用
试试这个:
=iif(Fields!Gender.Value="1","Male", iif(Fields!Gender.Value="2","Female","Undefined"))
格式为:
=iif(expression=value, true, false)
你可以改变:
=iif(expression=value, true, iif(expression2=value2, true, false))
【讨论】:
开关和自定义代码看起来不错,谢谢大家
但是如果你坚持使用 iif() 条件的话,
=iif( (Fields!Gender.Value="1"), "Male", iif( (Fields!Gender.Value="2"), "Female", "Something Else" ) )
好的,再见
【讨论】: