【问题标题】:How to set width for ReportViewer for MVC如何为 MVC 的 ReportViewer 设置宽度
【发布时间】:2015-11-07 15:43:32
【问题描述】:

我正在使用ReportViewer for MVC 在我的 MVC 应用程序的视图中显示报告。
如何设置此控件的宽度?

我已将宽度设置为 100%,但它不起作用,如此屏幕截图所示。

在我看来,我使用:

<div>
    @Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { scrolling = "yes", width = "100%" })
</div>

而aspx页面是:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="margin: 0px; padding: 0px;width:100%;">
<form id="form1" runat="server">
<div  style="width:100%">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="ReportViewerForMvc"     Name="ReportViewerForMvc.Scripts.PostMessage.js" />
</Scripts>
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%"  Height="600px"></rsweb:ReportViewer>
</div>
</form>
</body>

【问题讨论】:

  • @johan 用代码更新了问题。

标签: c# asp.net-mvc-4 reportviewer


【解决方案1】:

尝试在控制器中编写以下代码

using System.Web.UI.WebControls;

  ReportViewer reportViewer = new ReportViewer();
  reportViewer.ProcessingMode = ProcessingMode.Local;
  reportViewer.SizeToReportContent = true;
  reportViewer.Width = Unit.Percentage(100);
  reportViewer.Height = Unit.Percentage(100);

【讨论】:

  • 为什么将ProcessingMode设置为Local?仅当我将其设置为 Remote 时它才对我有效。
  • 对我来说,加载完成后宽度为 100%,但加载时的宽度不像图片中那样 picpaste.com/width-VaOqaz2X.png 知道为什么会这样
【解决方案2】:

注意:我正在使用来自 nuget 的 ReportViewerForMvc

我发现我需要从两个方面解决宽度/高度问题 - 我在 ReportViewerWebForm.aspx 加载时添加了一个 CSS 来修改 iframe。

iframe {
  /*for the report viewer*/
  border: none;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}

除了我删除之外,其余部分与接受的答案相同

reportViewer.SizeToReportContent = True

来自我的控制器,因为它隐藏了我在同一个 Report.cshtml 中呈现的更广泛的报告所需的滚动条

@using ReportViewerForMvc; @{ ViewBag.Title = " Report"; }

<h2>Simple Report </h2>

@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)

我的控制器:

 > 

 public ActionResult ReportByType()
        {
            var data =SomeFunction.CreateDataTable(GetReportDataFromDB());

            ReportViewer reportViewer = new ReportViewer();
            reportViewer.ProcessingMode = ProcessingMode.Local;

            reportViewer.LocalReport.ReportPath = 
              Request.MapPath(Request.ApplicationPath) + 
                   @"Views\Reports\ReportByType.rdlc";
            reportViewer.LocalReport.DataSources.Add(new 
               ReportDataSource("DataSet1", data));
           // reportViewer.SizeToReportContent = true; ---hides the scrollbar which i need
            reportViewer.Width = Unit.Percentage(100);
            reportViewer.Height = Unit.Percentage(100);

            ViewBag.ReportViewer = reportViewer;
            return PartialView("Report");

        }


        enter code here

【讨论】:

  • 对我来说,加载完成后宽度是 100%,但加载时的宽度不像图片中那样picpaste.com/width-VaOqaz2X.png 知道为什么会这样
  • 不确定。不知道你是如何连接它的......(不能在图片上用红色的文本变红)......也许你应该确保 CSS 将 iframe 大小设置为足以显示微调器......所以当你触发加载事件,它看起来不会那么糟糕。匹配颜色以使其看起来光滑。加载后,报告将处理大小 (100%)。希望这会有所帮助。
【解决方案3】:
@Html.ReportViewer(
     ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer,new { @width="100%"})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多