在传入空记录集时,将ReportViewer(在LocalMode中为10.0.0.0)直接呈现为PDF时出错

时间:2010-08-12 14:24:36

标签: .net reportviewer

我有一种实用方法(下面)一直很好用。在对报表控件进行数据绑定之后,我将控件传递给它,并将报表呈现为PDF。

我最近升级到.NET 4.0和新的2010报表查看器控件(10.0.0.0)。现在,如果我传递给reportviewer的记录集(数据集)没有任何数据,它会抛出错误(如下)。

有什么想法吗?谢谢!

错误(前5名):

[InvalidOperationException :(处理):ScalableList:索引0超出允许范围[0 :: - 1]] Microsoft.ReportingServices.Diagnostics.Utilities.DefaultRSTraceInternal.Assert(Boolean condition,String componentName,String message)+176 Microsoft .ReportingServices.OnDemandProcessing.Scalability.ScalableList 1.get_Item(Int32 index) +212 Microsoft.ReportingServices.Rendering.HPBProcessing.PageStructStaticMemberCell.AddToPageCHContent(List 1 rowHeights,ScalableList`1 columnInfo,Int32 rowIndex,Int32 colIndex,Boolean isLTR,RPLWriter rplWriter,PageContext pageContext,Double pageLeft,Double pageTop,Double pageRight,Double pageBottom,RepeatState repeatState ,布尔& hasLabels)+60 Microsoft.ReportingServices.Rendering.HPBProcessing.Tablix.AddToPage(RPLWriter rplWriter,PageContext pageContext,Double pageLeft,Double pageTop,Double pageRight,Double pageBottom,RepeatState repeatState)+781

实用方法:

private static void renderReportAsPDF(ReportViewer reportViewer,HttpResponse response)         {

        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;
        string reportName = reportViewer.LocalReport.DisplayName;
        byte[] bytes = reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding,out extension, out streamids, out warnings);

        response.Clear();
        response.ContentType = mimeType;
        response.ContentEncoding = System.Text.Encoding.UTF32;            
        response.BinaryWrite(bytes);
        response.End();

}

1 个答案:

答案 0 :(得分:0)

在VS2010中打开rdlc文件并让它升级文件的格式修复了问题。在.NET 4.0之前,报告运行良好,没有旧的2008格式的记录集。