How to let ReportViewer in ASP.net 2.0 local mode to change Report definition

If reportviewer is used in Form application, ReportPath can be set.

But in asp.net the same method does not work.

    protected void Button1_Click(object sender, EventArgs e)
    {

                if (this.strOrderBy == "Customer")
                {
                    this.rvPrice.LocalReport.ReportPath = @"Report\PriceCustomer.rdlc";
                 }
                else
                {
                    this.rvPrice.LocalReport.ReportPath = @"Report\PricePart.rdlc";
                 }

......

}

Report definition is still the old one.



Answer this question

How to let ReportViewer in ASP.net 2.0 local mode to change Report definition

  • RG6

    For information the:

    Me.ReportViewer1.Reset()

    Is now in VS2005 SP1. This will allow you to change the report dynamically eg:

    Dim DataTable As New DataSetReports.DataTable_MainPDFDataTable

    Dim DataRow As DataSetReports.DataTable_MainPDFRow = CType(DataTable.NewRow, DataSetReports.DataTable_MainPDFRow)

    DataRow.BodyText = Me.uiTextBoxBody.Text

    DataTable.Rows.Add(DataRow)

    Me.ReportViewer1.Reset()

    Me.ReportViewer1.LocalReport.ReportPath = "Reports/MainCommunication.rdlc"

    Me.ReportViewer1.LocalReport.DataSources.Clear()

    Dim DataSource As Microsoft.Reporting.WebForms.ReportDataSource = _

    New Microsoft.Reporting.WebForms.ReportDataSource("DataSetReports_DataTable_MainPDF", DataTable)

    ReportViewer1.LocalReport.DataSources.Add(DataSource)

    ReportViewer1.LocalReport.Refresh()


  • harrha19

    You are instantiating a new instance of the viewer, but it is not being associated with the webform.  The old instance is still the one being rendered.  Try something like this:

    ControlCollection coll = oldViewer.Parent.Controls;
    int oldIndex = coll.IndexOf(oldViewer);
    ReportViewer newViewer = new ReportViewer();
    coll.AddAt(oldIndex, newViewer);
    coll.Remove(oldViewer);


  • koolsandy

    thanks a lot for this wonderful information...

    now my problem is that how can i bind image to rdlc..

    thanks in advance



  • Turru

    Thanks this was helpful. Here was my additions to replace the current ReportViewer control on the ASP.NET page. Any ideas when the Reset() command like in Winforms will be available in Webforms Thanks again.

    ReportViewer oldViewer = this.ReportViewer1;

    ControlCollection coll = oldViewer.Parent.Controls;

    int oldIndex = coll.IndexOf(oldViewer);

    ReportViewer ReportViewer1 = new ReportViewer();

    // Set Processing Mode

    ReportViewer1.ProcessingMode = ProcessingMode.Local;

    // Set reportviewer size

    ReportViewer1.Height = new Unit("550px");

    ReportViewer1.Width = new Unit("100%");

    ReportViewer1.ID = "ReportViewer1";

    // Set default values

    ReportViewer1.ShowExportControls = false;

    ReportViewer1.ShowBackButton = false;

    ReportViewer1.SizeToReportContent = true;

    // Reset the control collection position

    coll.AddAt(oldIndex, ReportViewer1);

    coll.Remove(oldViewer);


  • dmcgiv

    The latest information is available here: http://msdn.microsoft.com/vstudio/support/servicing/default.aspx


  • GTG

    I can't make any guarantees, but it is currently planned for Visual Studio 2005 SP1.
  • Ferry Meidianto

    Both winforms and webforms only allow you to set the report definition of a local report once.  In winforms, you can call ReportViewer.Reset() to cause the control to generate a new instance of LocalReport.  In webforms, you will need to instantiate a new instance of the control.
  • p818632

    Wow this is a major bug.  Any idea when SP1 is going to be out   Can you change anything without rebuilding the control Parameters Data Source
  • notoryus

    Thx Brian!

    But do you mean to do as follow

    protected void Button1_Click(object sender, EventArgs e)
        {

                    if (this.strOrderBy == "Customer")
                    {this.rvPrice = new ReportViewer();
                        this.rvPrice.LocalReport.ReportPath = @"Report\PriceCustomer.rdlc";
                     }
                    else
                    {this.rvPrice = new ReportViewer();
                        this.rvPrice.LocalReport.ReportPath = @"Report\PricePart.rdlc";
                     }

    ......

    }

    It seems does not work.


  • sabfix

    On possible solution is place both reports with separate reportviewer controls on the web page (configure datasources, GetData metod) and

    then leave only reportviewer on the page (delete all other reports reportviewer controls, but leave objectdatasources on the page )

    so,you must in PageLoad first remove existing ReportViewer Control

    ControlCollection coll = this.ReportViewerHouseFlats.Parent.Controls;

    //remember the place, there the old ReportViewer was

    int oldIndex = coll.IndexOf(this.ReportViewerHouseFlats);

    //remove in from the page

    coll.Remove(this.ReportViewerHouseFlats);

    //then add new control

    ReportViewer1 = new Microsoft.Reporting.WebForms.ReportViewer();

    ReportViewer1.Height = Unit.Parse("490px");

    ReportViewer1.Width = Unit.Parse("100%");

    coll.AddAt(oldIndex, ReportViewer1);

    this.ReportViewer1.LocalReport.DataSources.Clear()

    //and set new control report and datasources

    this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Raportid/HouseFlats.rdlc");

    this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("dsHouses_HOUSE_FLATS_FOR_WORKER_KUIDO_S", ObjectDataSourceHouseFlats));

    this.ReportViewer1.Visible = true;



  • How to let ReportViewer in ASP.net 2.0 local mode to change Report definition