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