ReportViewer参数,渲染pdf

时间:2011-08-30 19:44:29

标签: asp.net vb.net rdlc

我想直接向pdf呈现报告。我有一个带有2个参数的objectdatasource。我从webform上的hiddenfield和gridview上的datakeyname获取这些参数。当我在报表查看器中加载报表而不渲染为pdf时,报表可以正常工作。当我放置代码以将报告呈现为pdf时,参数不会加载,即报告呈现为pdf,但报告中没有详细信息。我的代码如下,任何帮助表示赞赏。我将代码放在gridview_selectedindexchanged:

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
    Dim ds1 As New seminarsTableAdapters.Sem1TableAdapter
    Dim rdssem As New ReportDataSource("seminars.sem1TableAdapter", ds1.GetData(aid:=HiddenField1.Value, semid:=GridView1.SelectedDataKey.Value))
    Dim reportsem As New LocalReport
    reportsem.ReportPath = "Report1.rdlc"
    Dim p1 As New ReportParameter("aid", HiddenField1.Value)
    Dim p2 As New ReportParameter("semid", GridView1.SelectedDataKey.Value().ToString)
    reportsem.SetParameters(New ReportParameter() {p1, p2})
    reportsem.DataSources.Add(rdssem)

    Me.ReportViewer1.LocalReport.Refresh()

    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
    Dim bytes As Byte()

    bytes = ReportViewer1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

    Response.Clear()
    Response.ContentType = mimeType
    Response.AddHeader("content-disposition", "attachment; filename=foo." + extension)
    Response.BinaryWrite(bytes)
    Response.End()

End Sub

1 个答案:

答案 0 :(得分:0)

我忽略了以下代码行:

Dim rdssem As New ReportDataSource(“seminars.sem1TableAdapter”,ds1.GetData(援助......

它应该读到:

Dim rdssem As New ReportDataSource(“ seminars.sem1 ”,ds1.GetData(help .....

现在工作正常!

谢谢!