2

我想一个(的.rdl)报告文件加载到一个web报表查看器控件(Visual Studio 2010的控制):负载RDL报告转换为Web报告查看器

//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); 
    } 

我缺少一行代码某处?我使用了与RefreshReport()相同的Winforms报表查看器 - 但是没有可以为Web报表查看器找到的等效方法)。该页面保持空白 - 我错过了什么?

回答

2

有一个.Refresh()方法,这就是你所缺少的。下面是我使用(以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() 
+0

好吧,我加了你所提到的线路,但这似乎并不成为问题 - 网页仍是空白.​​... – user559142 2012-01-13 12:14:08

+0

你在你的问题说您正在尝试加载RDL文件。它是RDL还是RDLC? RDLC是您需要的格式,C代表客户端。 RDL文件用于Reporting Services。 – 2012-01-13 12:51:55

+0

为什么我需要.rdlc?我有一个.rdl's - 不完全确定它们有什么区别?我得到了这个与winform.reportviewer – user559142 2012-01-13 14:21:50