1

我创建了一个本地报告,其中包含一些子报告。我正在尝试通过单击按钮将报告直接加载为 pdf。

我尝试使用报告查看器显示报告,它显示得很好,但是当我尝试直接呈现为 pdf 时,我收到有关数据源的错误。当我调试代码时,我注意到我的子处理函数确实会运行,直到按钮调用函数完成并引发错误。

Dim reportParam As New ReportParameter("appId", appid)
    Dim reportParam2 As New ReportParameter("appDate", appDate)
    Dim reportParam3 As New ReportParameter("auditDate", Now)
    Dim reportArray As New ReportParameterCollection
    reportArray.Add(reportParam)
    reportArray.Add(reportParam2)
    reportArray.Add(reportParam3)
    AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf    SetSubDataSource
     ReportViewer1.LocalReport.SetParameters(reportArray)
    ObjectDataSource1.SelectParameters("appID").DefaultValue = appid
    ObjectDataSource1.SelectParameters("appDate").DefaultValue = appDate
    ObjectDataSource1.DataBind()
    Dim warnings As Warning() = Nothing
    Dim streamids As String() = Nothing
    Dim mimeType As String = Nothing
    Dim encoding As String = Nothing
    Dim extension As String = Nothing
    Try
        ReportViewer1.DataBind()
        ReportViewer1.LocalReport.Refresh()

        Dim byteViewer As Byte()
        byteViewer = ReportViewer1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
        Response.Buffer = True
        'Response.Clear()

        Response.ContentType = mimeType
        Response.AddHeader("content-disposition", "attachment; filename=test.pdf")
        Response.BinaryWrite(byteViewer)
        Response.OutputStream.Write(byteViewer, 0, byteViewer.Length)
        Response.Flush()
        Response.Close()

提前感谢您的建议,我只是想弄清楚如何让报告在呈现之前而不是在此功能完成之后加载数据源。

4

0 回答 0