Nitin S
Nitin S

Reputation: 7601

Disable exporting RDLC report in EXCEL format

C# - How to disable exporting RDLC report in EXCEL format

enter image description here

Just want to hide the "Excel" option from the dropdownlist.

Upvotes: 3

Views: 4561

Answers (2)

Suhaib Janjua
Suhaib Janjua

Reputation: 3574

You can do this with an ease by using jquery below script.

$(document).ready(function () {
     $("a[title='Excel']").parent().hide();  // Remove from export dropdown.
     $("a[title='MHTML (web archive)']").parent().hide();  
     $("a[title='TIFF file']").parent().hide();  
});

Note: Excel, PDF, Word are case-sensitive. So you can hide any option you want without messing with code at code behind.

Upvotes: 3

Nitin S
Nitin S

Reputation: 7601

found it on net

#region "Disable Excel Export"
private void CustomizeRV(System.Web.UI.Control reportControl)
{

    foreach (System.Web.UI.Control childControl in reportControl.Controls)
    {

        if (childControl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
        {

            System.Web.UI.WebControls.DropDownList ddList = (System.Web.UI.WebControls.DropDownList)childControl;

            ddList.PreRender += new EventHandler(ddList_PreRender);

        }

        if (childControl.Controls.Count > 0)
        {

            CustomizeRV(childControl);

        }

    }

}


//Dropdown prerender event
//You can hide any option from ReportViewer( Excel,PDF,Image )

void ddList_PreRender(object sender, EventArgs e)
{
    System.Web.UI.WebControls.DropDownList ddList = (System.Web.UI.WebControls.DropDownList)sender;
    System.Web.UI.WebControls.ListItemCollection listItems = ddList.Items;

    if ((listItems != null) && (listItems.Count > 0) && (listItems.FindByText("Excel") != null))
    {
        foreach (System.Web.UI.WebControls.ListItem list in listItems)
        {
            if (list.Text.Equals("Excel"))
            {
                list.Enabled = false;
            }
        }
    }
}
#endregion

Upvotes: 1

Related Questions