13

here is my problem

I am working with Rdlc report. I have these fields:

First name  
Address1 
Address2  
City, state, zip

If any one of these fields is empty, it should not show the blank space. For example (expected output)

First name,  
Address1,  
City, state, zip  

But, as show in the above image, I am getting this:

First name,  
Address1,  
........................<-(blankspace is showing here)  
City, state, zip 

I tried changing Visiblity -> Expression -> =IIF(String.IsNullOrEmpty(Fields!Address2.Value), false,True)

Gianni B.
  • 2,691
  • 18
  • 31
Thiyagarajan
  • 327
  • 1
  • 6
  • 21

3 Answers3

24

I think that the expression with String.IsNullOrEmpty didn't works.

Try with one of this two options:

1.=IIF(IsNothing(Fields!Address2.Value),False,True)

2.=IIF(Len(Fields!Address2.Value) = 0,False,True)

According to the comments, the solution is to create a single textbox in which put two (or more) fields and concatenate the value if the second fields has a real value or is empty.

So the expression will be:

=Fields!Name.Value + System.Environment.NewLine + Fields!SAddr_Line1.Value + IIF(‌​Len(Fields!Address2.Value) = 0, "", System.Environment.NewLine + Fields!Address2.Value) + Fields!ShipTo.Value

For more readability:

=Fields!Name.Value
+ System.Environment.NewLine
+ Fields!SAddr_Line1.Value
+ IIF(‌​Len(Fields!Address2.Value) = 0, "", System.Environment.NewLine + Fields!Address2.Value)
+ Fields!ShipTo.Value
Gianni B.
  • 2,691
  • 18
  • 31
  • And, btw, if you are rendering in PDF this will not work as [explained here](http://technet.microsoft.com/en-us/library/dd255291%28v=sql.100%29.aspx). `Dynamic show and hide elements are not supported in PDF. The PDF document is rendered to match the current state of any items in the report. For example, if the item is displayed when the report is run initially, then the item is rendered. Images that can be toggled are not rendered, if they are hidden when the report is exported.` – Gianni B. Dec 12 '12 at 10:15
  • yes i am rendering the report in pdf...... do you know any other method. i just got the output through sql query. but i am not satisfied. i want to do with report properties.. – Thiyagarajan Dec 12 '12 at 11:18
  • 1
    what about only one textbox for the address? The expression will be something like that: `=Fields!Address1.Value + IIF(String.IsNullOrEmpty(Fields!Address2.Value),"", System.Environment.NewLine + Fields!Address2.Value)` – Gianni B. Dec 12 '12 at 11:50
  • any news about my last solution? – Gianni B. Dec 14 '12 at 09:46
  • 1
    yes it was great idea, i have your code with me... my report is huge, so i got my answer through sql server queries in single textbox as what u given in last code..... thank you Nanny – Thiyagarajan Dec 14 '12 at 09:59
  • Hi Nanny It is working dear, sorry i made small mistake that is why..=Fields!Name.Value+System.Environment.NewLine+Fields!SAddr_Line1.Value+IIF(Len(Fields!Address2.Value) = 0,"",System.Environment.NewLine+Fields!Address2.Value)+Fields!ShipTo.Value and one doubt empty quotes("")takes single space how to avoid it. – Thiyagarajan Dec 18 '12 at 06:25
  • Sorry I forgot about this question. I don't know why it appears a white space, are you sure that it's coming from the double quote? If yes, you can try with the `Trim` function like this: `IIF(‌​Len(Fields!Address2.Value) = 0,Trim(""),System.Environment.NewLine+Fields!Address2.Value)` – Gianni B. Dec 18 '12 at 07:49
  • yes you are right it comes from double quote, but if i use this Trim("") function i doesn't remove the single blank space. – Thiyagarajan Dec 18 '12 at 07:59
  • You can always concatenate the last field instead of the empty string: `=Fields!Name.Value + System.Environment.NewLine + Fields!SAddr_Line1.Value + IIF(Len(Fields!Address2.Value) = 0, System.Environment.NewLine + Fields!ShipTo.Value, System.Environment.NewLine + Fields!Address2.Value + System.Environment.NewLine + Fields!ShipTo.Value)` – Gianni B. Dec 18 '12 at 08:00
1

Just in case this helps somebody.

I suffered the same (and I had quite complex grouping on) until I did:

Fields!FieldName.Value * 1

(You can then convert to String using CStr() if needed)

And voilà!

Ramon Araujo
  • 1,743
  • 22
  • 31
  • This works fine for me but why? Is it that NULL * 1 = 0? – cosan May 20 '19 at 07:09
  • 1
    Hi @cosan, That is happening because of the magic of Type Inference (https://en.wikipedia.org/wiki/Type_inference). So, the resulting data type is inferred from the operators and operands involved in the expression. Hope that explains it ;) – Ramon Araujo May 24 '19 at 04:22
0

You Can Use if else statement in the following cases in rdlc report

     1=IIF(IsNothing(Fields!Amount.Value),False,True)
     2.=IIF(Len(Fields!Amount.Value) = 0,False,True)

       =iif(IsNothing(Sum(Fields!Amount.Value)),0.00,True).ToString()

last one when no records found and display 0 its working!

Sam
  • 111
  • 3
  • 7