【问题标题】:Paging not working in Report Viewer分页在报表查看器中不起作用
【发布时间】:2019-12-01 06:09:02
【问题描述】:

我目前遇到了报告查看器控件的问题。我当前的项目是一个 MVC3 应用程序,我在其中链接一个带有 Report Viewer 控件的 aspx 页面。页面显示,但是,我根本无法翻阅结果。这是我的代码。

报告.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="SOSNG.Reports.Report" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
    <head id="Head1" runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="X-UA-Compatible" content="IE=8" />
        <title>Report Viewer</title>
        <link rel="stylesheet" href="../Content/Site.css"" type="text/css" />
    </head>
    <body>
        <noscript><div class="noScript"><span class="errorMessage"></span>- This application works best with Javascript enabled.</div></noscript>
        <div class="page">

            <div id="MastHead">
                <div id="MastHeadLeft"></div>

                    <%--<h1 id="ApplicationName"><span class="Skip"></span></h1>--%>

                <div id="MastHeadRight"></div>

                <div id="MasterMenu" class="clear"> 
                </div>

            </div>

            <div id="MainPalette">
                <div class="SubPalette"><h3 class="PaletteName"></h3>
                    <div class="SubPaletteContent">
                    <br />
                        <form id="form1" runat="server">
                            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                            <div>
                                <rsweb:ReportViewer ID="SOSNGReportViewer" runat="server" AsyncRendering="False" 
                                Height="100%" SizeToReportContent="False" Width="100%" ZoomPercent="100" 
                                Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
                                     WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
                                     ProcessingMode="Remote" ShowParameterPrompts="false">

                                 </rsweb:ReportViewer>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <div id="Footer">
                <div id="FooterSpan"></div>
                <div id="FooterLeft"></div>
                <div id="FooterRight"></div>
            </div>

        </div>

    </body>
</html>

报告.aspx.cs

protected void Page_Load(object sender, EventArgs e)
        {
            //Report Type
            var reportType = (string)Session["ReportType"];

            //Search parameters
            var searchFBINumber = string.Empty;
            var searchVlanId = string.Empty;
            var searchNetworkDevice = string.Empty;
            var searchMACAddress = string.Empty;
            var searchLocation = string.Empty;
            var searchIPAddress = string.Empty;
            var searchComment = string.Empty;

            //Server Report setup
            var serverReport = SOSNGReportViewer.ServerReport;
            serverReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServer"]);
            serverReport.ReportPath = ConfigurationManager.AppSettings["ReportDirectory"] + reportType;

            Microsoft.Reporting.WebForms.ReportParameter[] RptParameters;

            //Switch on Report
            switch (reportType)
            {
                case "CommentReport":
                    searchComment = (string)Session["Comment"];
                    if (!string.IsNullOrEmpty(searchComment))
                    {
                        RptParameters = new ReportParameter[1];
                        RptParameters[0] = new ReportParameter("Comment", searchComment);

                        this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                        this.SOSNGReportViewer.ServerReport.Refresh();
                    }
                    break;
                case "FBINumberReport":
                    searchFBINumber = (string)Session["FBINumber"];
                    if (!string.IsNullOrEmpty(searchFBINumber))
                        searchFBINumber = null;

                    RptParameters = new ReportParameter[1];
                    RptParameters[0] = new ReportParameter("FBINumber", searchFBINumber);

                    this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                    this.SOSNGReportViewer.ServerReport.Refresh();
                    break;
                case "IPAddressReport":
                    searchIPAddress = (string)Session["NetworkIPAddress"];
                    if (!string.IsNullOrEmpty(searchIPAddress))
                    {
                        RptParameters = new ReportParameter[1];
                        RptParameters[0] = new ReportParameter("IPAddress", searchIPAddress);

                        this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                        this.SOSNGReportViewer.ServerReport.Refresh();
                    }
                    break;
                case "LocationReport":
                    searchLocation = (string)Session["Location"];
                    if (!string.IsNullOrEmpty(searchLocation))
                        searchLocation = null;

                    RptParameters = new ReportParameter[1];
                    RptParameters[0] = new ReportParameter("Location", searchLocation);

                    this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                    this.SOSNGReportViewer.ServerReport.Refresh();
                    break;
                case "MACAddressReport":
                    searchMACAddress = (string)Session["MACAddress"];
                    if (!string.IsNullOrEmpty(searchMACAddress))
                        searchMACAddress = null;

                    RptParameters = new ReportParameter[1];
                    RptParameters[0] = new ReportParameter("MACAddress", searchMACAddress);

                    this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                    this.SOSNGReportViewer.ServerReport.Refresh();
                    break;
                case "NetworkDeviceReport":
                    searchNetworkDevice = (string)Session["NetworkDevice"];
                    if (!string.IsNullOrEmpty(searchNetworkDevice))
                        searchNetworkDevice = null;

                    RptParameters = new ReportParameter[1];
                    RptParameters[0] = new ReportParameter("NetworkDevice", searchNetworkDevice);

                    this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                    this.SOSNGReportViewer.ServerReport.Refresh();
                    break;
                case "VlanNumberReport":
                    searchVlanId = (string)Session["VlanId"];
                    if (!string.IsNullOrEmpty(searchVlanId))
                    {
                        RptParameters = new ReportParameter[1];
                        RptParameters[0] = new ReportParameter("VlanId", searchVlanId);

                        this.SOSNGReportViewer.ServerReport.SetParameters(RptParameters);
                        this.SOSNGReportViewer.ServerReport.Refresh();
                    }
                    break;
                default:
                    break;
            }
        }

【问题讨论】:

  • 当你说“不工作”时,你是什么意思?是分页没有显示,还是单击它但没有任何反应,或者它给出了 404?
  • 您的服务器日志或 IIS 日志中是否出现任何错误或 404?
  • 在下面查看我的答案。分页只是没有工作。当我单击如上图所示的箭头时,什么也没发生。我发现这是因为我没有检查 Post Back。

标签: asp.net reportviewer


【解决方案1】:

我想通了。我需要在开始时检查 !IsPostBack。每个 PostBack 只是重新绑定数据并重置控件。应该知道这很简单。

【讨论】:

    【解决方案2】:

    不久前我遇到了同样的问题。 添加这行简单的代码以防止回发,您的分页问题将得到修复。

    if (!IsPostBack){ //enter your report logic here }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多