Partilhar via


FAQ: How do I Hide Export Options with Local Report?

Question

I am using the ReportViewer control to show local reports in an ASPX page.

The reports are displayed fine but I have one requirement. By default, the Export list contains the Excel and PDF options in ReportViewer2008, and also contains the Word option in the ReportViewer2010. Now I only want to keep the PDF option and remove the others. How could I achieve this?

 

Answer

Currently, this is a product limitation for customizing the export option directly of the ReportViewer control.

However, as a workaround, we can use JavaScript to remove the Word and Excel export options. Please refer to the steps below.

For ReportViewer 2008:

  • 1. Preview the web page which contains the ReportViewer control.
  • 2. Check the source code of page. Find the id of the <select> node which contains the export options.
    e.g. It is " ReportViewer1_ctl01_ctl05_ctl00" in my page.
  • 3. In the ASPX file, add the JavaScript below:

<script type="text/javascript">
        window.onload = function() {
            var formatDropDown = document.getElementById('ReportViewer1_ctl01_ctl05_ctl00');
            if (formatDropDown != null) {
                formatDropDown.remove(1);
            }
        }
</script>

 

For ReportViewer 2010:

  • 1. Preview the web page which contains the ReportViewer control.
  • 2. Check the source code of page. Find the id of the <div> node which contains the export options.
    e.g. It is "ReportViewer1_ctl06_ctl04_ctl00_Menu" in my page.
  • 3. In the ASPX file, add the JavaScript below:

<script type="text/javascript">

    window.onload = function () {

        var formatDropDown = document.getElementById('ReportViewer1_ctl06_ctl04_ctl00_Menu');

        var formats = formatDropDown.childNodes;

        if (formatDropDown != null) {

            formatDropDown.removeChild(formats[0]);

            formatDropDown.removeChild(formats[1]);

        }

    }

</script>

 

Please correct the element id based on your web page. As a result, only the PDF export option still exists.

  

Applies to

Visual Studio 2008

Visual Studio 2010

Comments

  • Anonymous
    June 12, 2011
    I'm using Master page, when I see the view source of the page the control ID append with "ctl00_PlaceHolderMain_ReportsControl..................". I believe this could be a problem it might be changed in future case.  Please let me know can we get "ClientID" of this control and check? Else, if any other way this could be achieve?

  • Anonymous
    July 10, 2011
    Hi Paul, As you posted, the client element ID of the Export controls in the ReportViewer might be changed. Since there is no exposed method to get the “ClientID” dynamically, we have to check the ID in the source code manually when previewing the web page after it has been developed, and then add the JavaScript snippet. As another approach, we can also implement customized export UI. Please refer to the samples for ReportViewer at code.msdn.microsoft.com/reportviewer. There's a "CustomToolbar" sample that implements a custom toolbar.