Saleh
Saleh

Reputation: 2719

Need help with report expression - RDLC

I have a column type int and I want to check the value to display string instead of the number.

I added this expression

=IIf(Fields!Categ.Value = 1, "First", "")
=IIf(Fields!Categ.Value = 2, "Second", "")
=IIf(Fields!Categ.Value = 3, "Third", "")
=IIf(Fields!Categ.Value = 4, "Fourth", "")
=IIf(Fields!Categ.Value = 5, "Fifth", "")

but it is not working.

How can I do it?

Upvotes: 1

Views: 4017

Answers (3)

Coder22
Coder22

Reputation: 109

To add embedded code to a report, use the Code tab of the Report Properties dialog box. The code block you create can contain multiple methods. Methods in embedded code must be written in Microsoft Visual Basic and must be instance-based.

so for example:

public function getDescription(cat as integer) as string

dim sRet as string

select case cat

  case 1: sRet = "first"

  case 2: sRet = "second"

  case else 

   sRet = "uh?"

end select

return sRet

end function

then use the expression:

=code.getDescription(fields!Categ.value)

Upvotes: 0

DarkStar33
DarkStar33

Reputation: 221

I believe the values returned by the .value condition are strings so you could either have to cast them or do a string comparison.

String Comparison =IIf(Fields!Categ.Value == "1", "First", "")

Int Cast =IIf(Int.Parse(Fields!Categ.Value) == 1, "First", "")

Its been awhile since I have worked with RDLC.

Upvotes: 0

Bala R
Bala R

Reputation: 108937

Can you try this?

=Switch(
    Fields!Categ.Value = 1, "First", 
    Fields!Categ.Value = 2, "Second", 
    Fields!Categ.Value = 3, "Third", 
    Fields!Categ.Value = 4, "Fourth",
    Fields!Categ.Value = 5, "Fifth",
    Fields!Categ.Value > 5, "",
    Fields!Categ.Value < 1, "",
 )

Upvotes: 3

Related Questions