An attempt to dynamically assign RDLC's to Report viewers


P

Plateriot

I have a routine that uses a sqlDataReader to determine whether or not to
display a chart in a grid slot of possible 20 slots- thus far, it
successfully assigns the 'reportpath' to the report viewer dynamically,
enabling a contigious set of charts to appear, whether 3 in a row, or 20-
instead of having say-3 charts take up wasted space of 20 unused grid slots.

To illustrate, the portion that works 90% to my requirements is:

Do While dr.Read


'determine the report to insert based on the MeasureID that it
found
strMeasure = dr("MeasureID")
strReportPath = "Reports/rptPCPQual_" & strMeasure & ".rdlc"


i = i + 1

Select Case i

Case 1
rv1.Visible = True
rv1.Reportpath = strReportPath


Case 2
rv2.Visible = True
rv2.Reportpath = strReportPath
Case 3 .....


Of course, I then discovered that the report definition needs to be
completely removed and rebuilt in order of this to work properly so I'd like
to use the following code in place of the line rv.ReportPath = strReportpath
-- to read
ClearReport(Me.rv1, strReportPath)
(Me.rv1 is changed in each iteration to Me.rv2, Me.rv3...)
And here's what I'm attempting:

Private Sub ClearReport(ByVal CurRV As
Microsoft.Reporting.WebForms.ReportViewer, ByVal strReportPath As String)
Dim cc As ControlCollection = CurRV.Parent.Controls
'get index of previous ReportViewer so we can swap it out.
Dim prevIndex As Integer = cc.IndexOf(CurRV)
Dim RV As Microsoft.Reporting.WebForms.ReportViewer

' Remove previous ReportViewer
cc.Remove(CurRV)

'add new instance of ReportViewer.
RV = New Microsoft.Reporting.WebForms.ReportViewer()

' Reset report properties.
RV.ID = CurRV.ID
RV.Height = Unit.Parse("336px")
RV.Width = Unit.Parse("448px")


'Add the new ReportViewer to the previous ReportViewer location.
cc.AddAt(prevIndex, CurRV)

' Clear out any previous datasources.
RV.LocalReport.DataSources.Clear()

'Set report mode for local processing.
RV.ProcessingMode = ProcessingMode.Local


RV.LocalReport.ReportPath = strReportPath

RV.LocalReport.DataSources.Add(New
Microsoft.Reporting.WebForms.ReportDataSource("GetPCPQualityDataforallMonths", Me.odsPCPQual))
' Refresh the ReportViewer
RV.LocalReport.Refresh()
End Sub

Theoretically it should work, but I just see a blank sheet -
What did I miss?
 
Ad

Advertisements


Top