user41340
问问题
4555 次
1 回答
2
我发现如何做到这一点的唯一方法是创建一个自定义的“导出”功能......这真的很简单。
第 1 步:在您的报告中创建一个名为“ShowImage”的参数。我使用了字符串的数据类型,隐藏了提示并设置了默认值“False”。这样,当报表首次在页面上的报表查看器中运行时,它不会被隐藏。
第 2 步:将图像的可见性属性更改为具有以下内容的表达式:
=CBool(Parameters!ShowImage.Value)
第 3 步:隐藏报表查看器上的导出控制。这是我的例子:
<rsweb:ReportViewer ID="ReportViewer1" runat="server" ShowExportControls="false" Font-Names="Verdana" Font-Size="8pt">
<LocalReport ReportPath="Report1.rdlc" >
</LocalReport>
</rsweb:ReportViewer>
第 4 步:向您的页面添加一个按钮并编写自定义导出代码。您需要确保设置在步骤 1 中创建的参数。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create ReportViewer
Dim viewer As New Microsoft.Reporting.WebForms.ReportViewer()
Dim p(0) As Microsoft.Reporting.WebForms.ReportParameter
p(0) = New Microsoft.Reporting.WebForms.ReportParameter("ShowImage", "True")
viewer.LocalReport.ReportPath = Server.MapPath("Report1.rdlc")
viewer.LocalReport.SetParameters(p)
'Export to PDF
Dim reportContent As Byte() = viewer.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
'Return PDF
Me.Response.Clear()
Me.Response.ContentType = "application/pdf"
Me.Response.AddHeader("Content-disposition", "attachment; filename=Report.pdf")
Me.Response.BinaryWrite(reportContent)
Me.Response.End()
End Sub
而已。请问,您为什么不想创建自定义导出事件?
于 2009-03-03T21:17:48.613 回答