C# - How to disable exporting RDLC report in EXCEL format
Just want to hide the "Excel" option from the dropdownlist.
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.
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
精彩评论