none
Viewing Multiple Reports in a Single ReportViewer RRS feed

  • Question

  •  I am using SQL Server 2000 Reporting services, and I am trying to do something that SHOULD be very simple: view multiple reports using the same ReportViewer control.  In past projects, I have done something very simple to view a report, like this:

    'Set the report path of the report viewer  
    ReportViewer1.LocalReport.ReportPath = sReportPath  
     
    'Set the data source of the report to  
    'the dataview returned by a Stored Procedure.  
    ReportViewer1.LocalReport.DataSources.Clear()  
    ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource(sDataSetName, MyDV.Table))  
    ReportViewer1.DataBind() 

    This works well for the FIRST report I view.  When I click a button on the web page (that causes a different report file to be selected), I get an error:

    A data source instance has not been supplied for the data source "dsCurrentOpen_usp_ReportCurrentOpen".

    This error message is telling me that the ReportViewer is still looking for the FIRST data source (which should have been cleared using the DataSources.Clear()  method.

    I did some research, and found this article, which says that doing
    this in Web forms is impossible:
    http://aspalliance.com/762

    Also, this post shows how to dynamically create report viewer controls
    to "switch" between different reports:
    http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/browse_thread/thread/1fa8cbeff446a0a4/bd88dc5d6335a484?lnk=gst&q=DataSources.Clear#bd88dc5d6335a484

    This has other issues associated with creating controls dynamically, as you can't reference them in code.

    In my mind, this is ridiculous.  Why even have a ReportViewer control, if it can't switch between different reports?  Hopefully I am missing something and someone can point me in the right direction.  I would greatly appreciate any suggestions or comments anyone might have.

    Thank you!

    • Edited by Loki70 Thursday, December 11, 2008 4:02 PM formatting
    Thursday, December 11, 2008 4:01 PM

Answers

  • Prior to setting the new report path, you need to call ReportViewer1.Reset().
    • Marked as answer by Loki70 Monday, December 15, 2008 3:29 PM
    Sunday, December 14, 2008 8:27 PM
    Moderator

All replies

  • Prior to setting the new report path, you need to call ReportViewer1.Reset().
    • Marked as answer by Loki70 Monday, December 15, 2008 3:29 PM
    Sunday, December 14, 2008 8:27 PM
    Moderator
  • Brian - that was it!  I tried .Close & .Dispose methods, but I never tried the .Reset method.

    Thank you very much for your very helpful post!  You save me from a real maintenance nightmare.
    Monday, December 15, 2008 3:30 PM