Posted by beakersoft | Posted in SQL Reporting Services | Posted on 24-12-2007
Images. They can make your reports look great, but sometimes they are a bit tricky to show where you want, and when you want. Even something as simple as showing an image or not, or showing a different image based on the condition of some data.
Well, it might not be rocket science (or rocket engineering) but its not exactly well documented, so here are a couple of real world examples of how to handle images in your reports.
First of all this is how to show or hide an image in a table, based on the condition of filed in your data set. This could be used to indicate (for instance) if an order is stopped. The first thing to do is add an image holder into your table. When you drag the image holder onto the cell of the table the image wizard will open. Follow the Wizard through and embed the image in your report. When its done you will see the image in the table cell.
Now, on the properties of the cell, drop down the Visible -> Hidden property, and click in Expression in the list, this will open up the expression editor. In here we are going to use an IIF statement to check the condition of one of our fields. We can then set the Visible state to true or false depending on the outcome. The statement will look something like:
=iif(Fields!Stop_Stat.Value = “Stop”, False, True)
With this now in place, when you run the report it should now only show the image when the value of Stop_Stat is true.
Changing the Image
The will be some circumstances where you want to show a different image depending on the value of a variable. This is done in a similar way to hiding the image, but instead you Data value of the image source.
The first thing to do is insert the images you need onto the report. Drop an image control onto your table where you want it to apear, and embed the image into the report. Then drop another image control on the report, maybe in the header or somewhere out of the way. Embed the image again and this time set this controls Visible property to false. Now you have both the images you need in the report.
At this point make a note of the names of both of the images embedded in the report. They tend to be the name of the file you used without the extension.
Now, go into the property’s of the image control in the table, under Data -> Value drop down to Expression to open up the expression editor. Here we are going to use an IIF statement on a filed, and tell it to use one image if the condition is true, or a different one if it was false:
=iif(Fields!Stop_date.Value is nothing, “advert_incomplete_1″, “stop”)
When you save it you wont see the image in the box any more, it should have changed to this
Now, when you run the report, the images should swap round depending on what the value of your filed is, so you will end up with something like
Hopefully, you should now be able to make better use of images in your reports now, making them a bit better to look at and by using visual pointers instead of plain old text.