Changing Background Image in Report based on Parameter

11 posts, 1 answers
  1. Anthony
    Anthony avatar
    26 posts
    Member since:
    Mar 2009

    Posted 02 Feb 2011 Link to this post

    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  
  2. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 02 Feb 2011 Link to this post

    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.
  3. DevCraft banner
  4. Anthony
    Anthony avatar
    26 posts
    Member since:
    Mar 2009

    Posted 03 Feb 2011 Link to this post

    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
  5. Answer
    Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 03 Feb 2011 Link to this post

    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
  6. Anthony
    Anthony avatar
    26 posts
    Member since:
    Mar 2009

    Posted 03 Feb 2011 Link to this post

    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

  7. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 03 Feb 2011 Link to this post

    No problem.  Good luck with your project.
  8. siva sankar
    siva sankar avatar
    26 posts
    Member since:
    Mar 2011

    Posted 06 Aug 2011 Link to this post

    Hai,Iam also trying same like you,but i cannot access,plse give a detailed explanation with an example.
  9. Anthony
    Anthony avatar
    26 posts
    Member since:
    Mar 2009

    Posted 08 Aug 2011 Link to this post

    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
  10. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 08 Aug 2011 Link to this post

    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.
  11. siva sankar
    siva sankar avatar
    26 posts
    Member since:
    Mar 2011

    Posted 10 Aug 2011 Link to this post

    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.
  12. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 10 Aug 2011 Link to this post

    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 >>

Back to Top
DevCraft banner