Monday, April 11, 2011

How To: Change Image visibility on rdlc export

Hello Everybody, I Have an Image in rdlc report. in the report i set visibility to false I want that when I Export to PDF or EXCEL To set the Image visibility to true.

  • How do I do This?
  • Is The a way to Catch the Export Event ?
  • I don`t want to create a custom 'export'.

Thanks …

From stackoverflow
  • The only way I found out how to do it was by creating a custom 'export' function...which really is quite simple.

    Step 1: Create a parameter in your report called "ShowImage". I used the data type of String, made the prompt hidden and set a default value of "False". That way, when the report first runs 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 on your 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 code the custom export. You will need to be sure to set the parameter you 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
    

    That's it. May I ask, why didn't you want to create a custom export event?

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.