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)
Me.ReportViewer1.LocalReport.SetParameters(params)
' create the new report
Me.ReportViewer1.DataBind()
Me.ReportViewer1.LocalReport.Refersh()
A report with header or footer fields contents set to the report parameter values will display these on each page.
Cheers,
|