How to check multiple conditions in rdlc expression
Asked Answered
J

4

8

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?

Joycelynjoye answered 25/7, 2012 at 11:13 Comment(2)
Would you please mark the correct answer to help others find solution?Malnourished
@MuhammadOmarElShourbagy funny how this question was asked in 2012, mans been active last week and still hasn't "found his solution"Phenacaine
M
13

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?

Malnourished answered 17/3, 2013 at 11:27 Comment(0)
E
9

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)
Expressway answered 27/7, 2012 at 13:0 Comment(2)
Hey this is very good option to enter write a code in report.thanx..i found other solution of using the switch statement just like iif.even this will workZoochore
You mean IIf in one line in the expression box? That is hard to debug but it's useful tooExpressway
W
6

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))
Washstand answered 8/12, 2014 at 7:33 Comment(0)
S
3

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

Sepulchral answered 3/7, 2013 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.