我目前在使用Report Viewer控件时遇到问题。我当前的项目是一个MVC3应用程序,我在aspx页面中链接了Report Viewer控件。但是,页面显示,我根本无法翻阅结果。这是我的代码。
Report.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>
Report.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;
}
}
答案 0 :(得分:8)
我明白了。我需要检查一下!IsPostBack在开头。每个PostBack只重新绑定数据并重置控件。应该知道这很简单。
答案 1 :(得分:-1)
不久前,我遇到了同样的问题。 添加此简单的代码行以防止回发,您的分页问题将得到解决。
if (!IsPostBack){ //enter your report logic here }