I have been doing a little exploration of Reporting Services
. It is a strange beast, especially after focusing on web development for the past 6 or so years. It straddles the desktop and web, and sometimes I need to forcibly pull my head out of its web-first rut.
It has some very nice features when used in conjunction with the ReportViewer control on a web page -- paging and export to Excel and PDF are built-in. No code to write, nothing to configure. It is an excellent replacement for "dumb" report pages that just show a lot of data, but don't need to do much else.
The hardest mental hoop to jump through so far is that there are no CSS settings. I don't want to hard code fonts, colors, etc. for each textbox on the report, but I have yet to discover a way around this. I'm so used to CSS classes, which make it easy to globably change how whole sites work with a few key strokes. To get alternatiing colors in each row I set an expression for the background property like so...
=If(RowNumber(Nothing) mod 2 = 0, "#80C0FF", "White")
Which is simple enough, and I can select all the text boxes in a report and set the property for all of them, but if I have more than 2 reports and want to change the alternating color or font, etc. for all of them -- it will get very dull, very fast.
I'm thinking the way to do this is to set a code call for each textbox with a parameter. There is a facility to call functions for most (if not all) the property settings. So unless I can find a better "native" way, what I'll do is write a method that returns the
static string GetBackgroundColorFromClassName(string ClassName)
string BackgroundColor ="White"; //or some default color
BackgroundColor = ClassList[ClassName];
The ClassList in this case would be a NameValue collection. Would build it from a config file. Or maybe even rip it from the css file. Hmmm. Something to investigate.
Then in the N TextBox Background color properties I'd change the code to something like (i'm not sure of the exact syntax for referencing an external mehtod):
=If(RowNumber(Nothing) mod 2 = 0, GetBackgroundColorFromClassName("AltItem"), GetBackgroundColorFromClassName("Item"))
Speaking of properties...
There is some minor foo going on in the report designer. Select a text box in a report, right-click and select Properties, a tabbed properties dialog box appears. Hit the <F4> key instead and the ubiquitous properties window appears. There is some overlap, but there are also differences in what properties are available from each view and in how they are organized. At least the tabbed dialog can be accessed from the properties window by clicking on the last button on the top the window (the icon does resemble a tabbed dialog box with a bit of squinting).
It is confusing the first couple of times searching for where to set something. I've trained myself to hit <F4> because the properties window displays everything that is available in one view. Definitely beats hunting through the tabs.
And Now To Hyperlinks...
One of the glorious things about the web -- actually the foundation of its very usefulness -- is the hyperlink. The ability to dash off to something else of interest with a simple click is so common, I think we take for granted how revolutionary the idea was. Using hyperlinks in straight html reports is done without thought. And fortunately, Reporting Services does in fact allow for their existence. The Action Property
of the TextBox is where the ability to add a hyperlink is hidden. Selecting "Jump To URL" and adding a URL does just what you'd want it to do. You'll have to add some custom code to use app paths, etc. But for static URLs it is very straightforward.
There is one trifling annoyance, though the hyperlink is created easily, it is not styled as a hyperlink when the report renders. I manually did so with the color and text decoration properties. I want my CSS. Didn't realize how much I would miss it, stepping away from it ever so slightly.
Firefox's One Character Columns...
While Reporting Services does render reports in Firefox without too much kicking and screaming, it does collapse all the columns to one character width
. Very efficient use of horizontal space, but annoying for everything but sodoku
output. There is a workaround in the forum linked to above -- a hidden textbox with a fixed width across the entire report keeps it from collapsing in Firefox.
Finally, Data Sources and Temp Tables...
I always work with stored procedures, and Reporting Services supports using them as Data Sources. Visual Studio even has a wizard for creating a table adapter to wrap around a stored procedure. This works very well and makes it easy drag the output columns into the report. However, if the stored procedure is selecting from a temp table, then the table adpater won't work. The error returned is that #SomeTempTable is undefined. Which is perfectly true. It dies when the stored procedure completes, but the output ifrom the procedure is still there! Smells like bad encapsualtion to me. It shouldn't matter how the table is created, something is peeking too deep. The workaround, of course, is to create a real table that matches the output for the purposes of the data adapter and designer. At run time, the data table created from the stored procedure is added dynamically as the Data Source and the report does not give a hoot how it was created.