Visual Studio速成2012 - 动态调整的报表视图大小

问题描述:

我已经建立了一个基本的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宽度。

感谢您的帮助!

有这样的两种方式, 通过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脚本,用于将查看器的大小调整为整页。所以根据需要调整宽度。这不会让你得到你想要的,但有一些小的改变会让你得到你想要的。

希望这有帮助。