p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 (http://p2p.wrox.com/forumdisplay.php?f=251)
-   -   "ReportItems" collection re header/footer (http://p2p.wrox.com/showthread.php?t=45189)

cdubose July 13th, 2006 12:31 PM

"ReportItems" collection re header/footer
On page 270 of the book, in a section entitled "Working with the strengths and limitations of the architecture", there is a table that enumerates many of the limitations and offers workarounds and alternatives.

For the limitation "Page header and footer cannot reference field values", one of the alternatives offered is "Place hidden text boxes in the report body and then reference these in the ReportItems collection".

That's it -- nothing else. A check of the index shows no further references to "ReportItems collection".

I presume this is done as custom code or in the "code" box?

How exactly would this be done?


dduvarney July 13th, 2006 12:43 PM

The Report Items collection can be used in expressions. Very similar to how you use the fields colleciton. If you want to reference the field "FirstName" your texbox will contain the expression "=Fields!FirstName.Value".

So, if you put a textbox on your report called "MyTextBox", you can reference it using its name. In your header place another textbox and give it the expression "=ReportItems!MyTextBox.Value". If that doesn't work, try "=ReportItems!MyTextBox.Text".

cdubose July 13th, 2006 01:05 PM

Thank you!


jmbaute August 2nd, 2006 04:21 PM

I've noticed that if your report spans multiple pages, the textboxes in the header seem to lose the reference to the hidden cell beyond page one...is there a way around this?

cdubose August 2nd, 2006 07:32 PM

I JUST discovered this myself!!! This is awful. I don't know the answer -- anyone??


jmbaute August 3rd, 2006 07:08 AM

My problem was (is) that my data table spans mulitple pages. I found a work around, though I am not satisfied it is the best solution: added a hidden column to my table, containing my hidden textbox referencing the parameter. As the table propogates to the other pages, so do the hidden fields.

Seems to work.

cdubose August 3rd, 2006 11:12 AM

Yes, I tried that too. It works in the Visual Studio preview.

However, when I exported the report to PDF format, it did not work. All the fields in header/footer that depended on hidden information in the tables were blank.

Unfortunately, we are required to use the PDF format for our reports, because of the quirk (feature?) in SSRS 2005 that makes HTML format come out wrong if there are overlapping elements. We just can't get away from overlapping elements in our reports.

I have come up with a solution, I think, that will work for me -- the header can apparently accept report parameters. Since the variable information in the header is consistent over an entire report in my case, this will work for me, though it's inconvenient. (Much of the information in the header previously came from just one report parameter, and now I have to send several.)

However, I have another problem. Our reports are required to have totals in the footer of each page. Originally, I tried picking up the data from the (hidden) table footer, and again, it worked in the Visual Studio preview, so I thought I had solved that problem. Much later, when I exported to PDF, I discovered that the footer fields came out blank. (Trust me, you didn't want to be within earshot of me when this discovery was made!)

The totals are required to be group totals -- totals from one of the groups in the table. That means that even if I used a subreport in the footer (which I don't even know will work), I would have to somehow send it the ID of the current group, and I don't know how to do that.

I may have to do something with code, saving the totals in global variables or the like -- but I don't know how to do that. It's a mess.


jmbaute August 3rd, 2006 12:13 PM

Ack...you're right. I also see that I get extra pages in my PDF, basically blank pages with a header inserted between the real data.

We may be the only ones posting here ?

Any ideas?


jmbaute <at> yahoo.com

cdubose August 3rd, 2006 01:06 PM

I think the problem with the extra pages is caused by the report being too wide for the PDF format. You can usually fix that by tweaking the margins in your report.

Unfortunately, the other problem is not so easily solved!

Yes, no one else seems to be hearing our problem, though surely others must have run into this.


jmbaute August 3rd, 2006 01:11 PM

Yep...somehow my page had drifted .125 inches. Well, I am out of ideas. Hopefully one of the experts will check in here soon. Good luck.


ucgtfh35 September 10th, 2006 08:52 PM

The data is processed seperately from the rendering of the report. ReportItems collection items have individual scopes and kludges in which fields are forced to repeat across pages can be used to set header/footer fields on those pages. Besides the ReportItems collection, Globals and Parameters can also be used to set header/footer field content. In a local report, parameter values may not be set to Field values. However, the ReportViewer webcontrol exposes the report's Parameters. Therefore, you can set the report parameters by using the ReportViewer's LocalReport SetParameters method. A couple of code behind examples:

    ' the first report parameter from a DropDownList
    Dim selectedItem As String = Me.DropDownList1.SelectedValue

    ' the second report parameter from an ObjectDataSource DataView DataRow Item
    ' (that is; a field)
    Dim irow As Integer = 0
    Dim icol As Integer = 0
    Dim activeView As System.Data.DataView = Me.ObjectDataSource2.Select()
    Dim cellItem As String = activeView.(irow)(icol).ToString()

    ' set the ReportViewer's parameters (same as the parameters defined in the report's .rdlc)
    Dim params(1) As Microsoft.Reporting.WebForms.ReportParameter
    param(0) = New Microsoft.Reporting.WebForms.ReportParameter("rpti d", selectedItem)
    param(1) = New Microsoft.Reporting.WebForms.ReportParameter("rptg rp", cellItem)
    ' create the new report

A report with header or footer fields contents set to the report parameter values will display these on each page.


ucgtfh35 September 10th, 2006 09:00 PM

oops, transcription error...

    params(0) = ...
    params(1) = ...

brewmanz July 21st, 2008 07:10 PM

I have multi-page lists-within-lists and it only shows the correct value on the first page heading of the report - in my case a Period End date that is the same for all records. I used the following trick to save the value (in this case a date field) for subsequent page headings:
In Report - Properties - Code
   Public Function StoreFirstValue_PeriodEndDateFromExtract(aDT as DateTime) as DateTime
        Static dtPeriodEndDateFromExtract as DateTime
        if dtPeriodEndDateFromExtract.Year < 999 then
            dtPeriodEndDateFromExtract = aDT
        end if
        return dtPeriodEndDateFromExtract
    End Function
the text box uses the following expression:
="Period Ending " & Code.StoreFirstValue_PeriodEndDateFromExtract(CDat e(First(ReportItems("textboxPeriodEndDateFromExtra ct").Value))).ToString("d MMMM yyyy")


All times are GMT -4. The time now is 01:33 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.