2013-10-01 91 views
0

我已經建立了一個基本的ReportView如下:Visual Studio速成2012 - 動態調整的報表視圖大小

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" ProcessingMode="Remote" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"> 
     <ServerReport ReportPath="/Reports/TestReport" ReportServerUrl="http://test/ReportServer" /> 
      </rsweb:ReportViewer> 

現在調整ReportView我可以做一些簡單的,如高度/寬度:

Height = "500px" Width = "300%" 

我甚至找到了超級便利的動態調整大小根據報告本身的大小中的ReportViewer:

AsyncRendering = "false" SizeToReportContent = "true" 

這樣做會擺脫ReportViewer周圍任何煩人的滾動條,因爲它會變得足夠大以適應整個報表。就高度而言,這很好,但是我需要報告的寬度始終保持在指定的值(使事情看起來不那麼雜亂)。

這可能嗎?例如,我可以以某種方式將寬度設置爲900px,然後使用SizeToReportContent或等效項,以便ReportViewer的高度根據報表本身的大小自動調整,而不會影響我設置的900px寬度。

感謝您的幫助!

回答

1

有這樣的兩種方式, 通過C#在pageLoad的

private void Page_Load(object sender, System.EventArgs e) 
    { 
     // Set Report's Current Page & Width. 
     ReportViewer.CurrentPage = Report.CurrentPage; 
     ReportViewer.Width = new Unit(Report.Width); 
     // Where Report.Width is the format "12in" 
     // I think it accepts pixels as well. I'm not positive though. 
    } 

通過JavaScript

function AdjustWidths() { 
    // This grabs the first div containing "1_" since the ReportViewer Div is "1_" + ReportViewerName. 
    // ReportViewerName being the Identifier in the C# PageLoad. (In the example above: "ReportViewer"). 
    var ReportViewerID = $($("div[id*=1_]")[0]).attr("id"); 
    // Sets the width equal to the inner "_fixedTable" which is the contents. 
    $("#" + ReportViewerID).css("width", $("#" + ReportViewerID + "_fixedTable").css("width")); 
} 

JavaScript方法並不完全證明(但是,我迄今爲止沒有任何問題)。這只是我創建的一個JQuery腳本,用於將查看器的大小調整爲整頁。所以根據需要調整寬度。這不會讓你得到你想要的,但有一些小的改變會讓你得到你想要的。

希望這有幫助。