Visual-studio – Load RDL report into Web Report Viewer

asp.netreporting-servicesvisual studioweb-applications

I am trying to load an (.rdl) report file into a web report viewer control (visual studio 2010 control):

    //Get the data and 
    .
    .
    //Add it to report
    ReportViewer.LocalReport.DataSources.Add(new ReportDataSource(element.Name, dt));

    //Pass the report to the viewer
    using (FileStream stream = new FileStream(ReportDocument.FileName, FileMode.Open))
    {
       this.ReportViewer.LocalReport.LoadReportDefinition(stream);
    }

Am I missing a line of code somewhere? I used the equivalent for the winforms report viewer with the addition of RefreshReport() – however there is no equivalent method that I could find for web report viewers). The page remains blank – what am I missing?

Best Answer

There is a .Refresh() method, and that is what you are missing. Here's what I'm using (in VB):

ReportViewer1.Reset()
ReportViewer1.LocalReport.Dispose()
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = Server.MapPath("/reports/" & ReportFile)
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource(<datasource>))
ReportViewer1.LocalReport.Refresh()
Related Topic