How to change image visibility when exporting rdlc

I have an image in an rdlc report. in the report I set the visibility to false I want it when I Export to PDF or EXCEL To set the visibility of the image to true.

  • How should I do it?
  • Is there a way to capture an export event?
  • I do not want to create a custom "export".

Thanks...

+3
source share
1 answer

The only way to find out how to do this is to create a custom export function ... it's really very simple.

Step 1. Create a parameter in your report called "ShowImage". I used the String data type, hid the tooltip, and set the default value to β€œFalse”. That way, when a report is first run in your report viewer on your page, it is not hidden.

Step 2. Change the visibility property for your image to an expression that has the following:

=CBool(Parameters!ShowImage.Value) 

Step 3. Hide the export controls in the report viewer. Here is my example:

 <rsweb:ReportViewer ID="ReportViewer1" runat="server" ShowExportControls="false" Font-Names="Verdana" Font-Size="8pt"> <LocalReport ReportPath="Report1.rdlc" > </LocalReport> </rsweb:ReportViewer> 

Step 4: add a button to your page and enter the export code. You need to set the parameter created in step 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 

What is it. May I ask why you do not want to create a custom export event?

+2
source

All Articles