Tuesday 17 June 2014

Displaying Checkboxes In An SSRS Report

Displaying Checkboxes In An SSRS Report

In this article I’ll be presenting those three methods.
Screenshots are made using SSRS 2012, and so is the Checkboxes.rdl available for download on my Skydrive.

Checkbox Control, huh?

You may be wondering why people would want to put a checkbox on a report.  After all, reports are not capable of accepting input – except through parameters but that’s a different story – and isn’t that what a checkbox is all about?
Not entirely.  Reporting Services is not only used for data exploration.  Sometimes people use it to produce data-driven printouts, such as letters or even checklists.  In that perspective, having checkbox control functionality would indeed be useful.

A Silly Scenario

My yummy pasta sauceMy imagination is failing me a little today so I came up with this silly example: a recipe checklist.  And today we’ll be cooking some pasta sauce!
This is the query that produces the list of ingredients:
select 'Yummy Pasta Sauce' as Recipe, 'zucchini' as Ingredient, 1 as Quantity, 'piece' as Unit, 1 as Needed
union select 'Yummy Pasta Sauce', 'mushrooms', 500, 'g', 1
union select 'Yummy Pasta Sauce', 'minced meat', 1, 'kg', 1
union select 'Yummy Pasta Sauce', 'Brussels sprout', 1, 'kg', 0
union select 'Yummy Pasta Sauce', 'onion', 2, 'piece', 1
union select 'Yummy Pasta Sauce', 'tomato sauce', 1, 'L', 1
union select 'Yummy Pasta Sauce', 'potato', 1, 'piece', 0
union select 'Yummy Pasta Sauce', 'Brussels sprout', 1, 'kg', 0
I’m cheating a bit here, all the data is hardcoded in the query.  Normally you’d of course have a database that contains your recipes.
And I’ve also introduced some ingredients which I wouldn’t really want in my sauce, such as Brussels sprouts. Silly, but it gives me a good excuse to use the red checkbox.
Time to explore the possibilities.

METHOD 1: IMAGES

I will not be going into full detail to explain the usage of images in SSRS reports.  If you need additional information on that, please first read my previous article that covers all possibilities of putting images on reports.
As I don’t have access to an inventory of stock images, I opened my favorite drawing program, Paint.NET, and created two images myself.  Then I embedded both images in the report:
Two images embedded in the report
I created a dataset using the query above.  Then I set up a Table with a group on the Recipe field whilst adding a header row to display the name of the recipe.
The row groups: Recipe > Details
The first column will show the ingredient details, using the following expression:
=Fields!Quantity.Value & " "
    & Fields!Unit.Value
    & " of " & Fields!Ingredient.Value
In the second column in the detail level cell, I did a drag & drop of one of my images.  That gives the following pop-up:
Dragging an image into the report brings up the Image Properties
Clicking the fx button brings up the brings up the Expression editor, in which I created the following expression:
=IIF(Fields!Needed.Value = 1, "checkbox_true", "checkbox_false")
Rendering the report shows us:
Using images to display checkboxes on a report

No comments:

Post a Comment