How to check multiple conditions in rdlc expression

ぐ巨炮叔叔 提交于 2021-01-27 03:58:12

问题


I have worked on only possible 2 in rdlc Expression values as like

=iif((Fields!Gender.Value="1"),"Male","Female")

Here I can work with only 2 possibilities. But if I want to check 3 or more conditions than how can I?


回答1:


Use the Switch if you have more conditions, it is also more readable.

=Switch(
    Fields!Gender.Value = 1, "Male", 
    Fields!Gender.Value = 2, "Female"
    )

rdlc expression iif use?




回答2:


You can use the Code property of the report. Right-click a blank space outside your report and click Report Properties or click the Report menu and click report properties.

Click the "Code" tab and type your condition checking statement as below

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

Then call the function in the expression of your textbox

= Code.GetGender(Fields!Gender.Value)



回答3:


try this one :

=iif(Fields!Gender.Value="1","Male", iif(Fields!Gender.Value="2","Female","Undefined"))

the format is :

=iif(expression=value, true, false)

you can change with :

=iif(expression=value, true, iif(expression2=value2, true, false))



回答4:


Switch and Custom Code look's nice, Thank you Guys

But if you insist using iif() condition then,

=iif( (Fields!Gender.Value="1"), "Male", iif( (Fields!Gender.Value="2"), "Female", "Something Else" ) )

Ok, Bye



来源:https://stackoverflow.com/questions/11648434/how-to-check-multiple-conditions-in-rdlc-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!