Report Viewer 隱藏匯出按鈕
Report Viewer 如果需要隱藏匯出按鈕,該怎麼做?
(很奇怪的需求,我知道。不過就是遇到了XD)
方法一,在.NET後端程式中隱藏Word和Excel按鈕:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// 此段要放在Page_PreRender中,若要隱藏PDF,把關鍵字”PDF”放入字串陣列中即可。 DisableExportButtons(this.RV_RdlViewer, new string[] { "Excel", "EXCELOPENXML", "IMAGE", "WORD", "WORDOPENXML" } ); // 主要處理函式 public void DisableExportButtons(ReportViewer ReportViewerID, string[] strFormatName) { try { FieldInfo FInfo; foreach (RenderingExtension RenExt in ReportViewerID.LocalReport.ListRenderingExtensions()) { foreach (string s in strFormatName) { if (RenExt.Name.Equals(s)) { FInfo = RenExt.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); FInfo.SetValue(RenExt, false); } } } } catch (Exception ex) { Logger.Error("DisableExportButtons ERRORS: ", ex); } } |
方法二,使用JQuery直接在頁面隱藏Report Viewer匯出按鈕:
1. 先在.aspx或MasterPage的<head></head>間引用JQuery Library
1 |
<script type="text/javascript" src="Script/jquery-1.11.0.min.js"></script> |
2. 在上句的後面,新增以下程式碼
1 2 3 4 5 6 7 |
<script type="text/javascript"> $(document).ready(function () { // 移除匯出按鈕 $("a[title='Excel']").parent().hide(); $("a[title='Word']").parent().hide(); }); </script> |