This is a migrated thread and some comments may be shown as answers.
Changing Background Image in Report based on Parameter
10 Answers 269 Views
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 02 Feb 2011, 01:58 PM
Is it possible to change the background image on a report based on a parameter or value returned by a function ?

I want to apply a watermark type image on the report but want to change it dependant on the state of the document content i.e. if i had a function that returned a string of "Draft" i would want to apply the Draft image to the whole report likewise if the function returned "Approved" i would want to apply the Approved image instead?

Is this possible ? if so could someone explain how to achieve this. If this isnt possible is there any work arounds ?

Thanks  

10 Answers, 1 is accepted

Sort by
0
Joel
Top achievements
Rank 2
answered on 02 Feb 2011, 11:06 PM
It's pretty easy if you use a parameter.  I have a bunch of client logo's saved in a report and show the appropriate logo based off of a clientid parameter that is passed

1.  Set your image up on the page and create a parameter of DraftStatus and make sure it looks like you want before you mess with the next steps.
2.  Right click on the image in design surface and select "Conditional Formatting"
3.  New Rule
4.  Expression        =Parameters.DraftStatus
5.  Operator            =
6.  Value                2
7.  Click "Style" button, Backgrounds  and set imagedata to the appropriate watermark for a draftstatus of 2.
Repeat for draftstatus of  X and Y and you should be all set.
0
Anthony
Top achievements
Rank 1
answered on 03 Feb 2011, 03:30 PM
Hi Joel

Thanks for the example using the conditional formatting, i did think about using this method.  I was originally wondering if it was possible to do this at the report level using the background image of the report. 

The method below requires that i add an image with conditional formatting on each of my report sections / groupings.

Thanks again for the help.

Tony
0
Accepted
Joel
Top achievements
Rank 2
answered on 03 Feb 2011, 03:54 PM
OK.  Misunderstood.  I never did a full page background image so this is just a guess. Did you try this?

Public Sub New()
        InitializeComponent()

If something = 1
     Me.Style.BackgroundImage = "img1.jpg"
else
    Me.Style.BackgroundImage = "img2.jpg"
end if

end sub


-Joel
0
Anthony
Top achievements
Rank 1
answered on 03 Feb 2011, 04:38 PM
Hi Joel

Thanks for the quick response, that worked a treat just had to modify the setting the image slightly

Me.Style.BackgroundImage.ImageData = System.Drawing.Image.FromFile("C:\DraftTransparent.png")

Thanks for the point in the right direction

0
Joel
Top achievements
Rank 2
answered on 03 Feb 2011, 04:55 PM
No problem.  Good luck with your project.
0
siva sankar
Top achievements
Rank 1
answered on 06 Aug 2011, 11:34 AM
Hai,Iam also trying same like you,but i cannot access,plse give a detailed explanation with an example.
0
Anthony
Top achievements
Rank 1
answered on 08 Aug 2011, 02:29 PM
Hi Siva

Not sure what you mean by cannot access ?

The way i resolved this was as Joel had described simply view the code for the report in the report class library.  Then in my example i wanted to access a report parameter named "Status" to determine which image to display.  So my code looked like :

Dim mySatus as String = Report.ReportParameters.Item("Status")
  
If myStatus = "Draft" Then 
Me.Style.BackgroundImage.ImageData = System.Drawing.Image.FromFile("C:\YourDocPath\Draft.png")
ElseIf myStatus = "Approved" Then 
Me.Style.BackgroundImage.ImageData = System.Drawing.Image.FromFile("C:\YourDocPath\Approved.png")
End If

Also think you will need a :
Imports System.Drawing
Imports System.IO
declaration to access the required classes. 

Thats is should be good to go with that.

Hope this helps.

Tony
0
Peter
Telerik team
answered on 08 Aug 2011, 05:07 PM
Hello Anthony,

You can set the Report.BackgroundImage.ImageData with a Binding. You will need an User Function that accepts a Report Parameter value and returns Image. Check out the following code snippet:

public static Image GetImage(object ParameterValue)
{
    string filename = ParameterValue.ToString();
    return Bitmap.FromFile(filename);
}
All the best,
Peter
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
siva sankar
Top achievements
Rank 1
answered on 10 Aug 2011, 06:58 AM
Thank you for your valuble answer, one more question, iam using table wizard in a report, when table has no data how to show a message("No Data To Display") in the table.
0
Steve
Telerik team
answered on 10 Aug 2011, 02:20 PM
Hi Siva,

This thread is opened by another user for another inquiry and we kindly ask you to restrain from "kidnapping" threads with questions on different topic. We would answer your inquiry in the other thread you have opened.

All the best,
Steve
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Asked by
Anthony
Top achievements
Rank 1
Answers by
Joel
Top achievements
Rank 2
Anthony
Top achievements
Rank 1
siva sankar
Top achievements
Rank 1
Peter
Telerik team
Steve
Telerik team
Share this question
or