I figured it out. I needed to do a check on !IsPostBack at the beginning. Each PostBack just rebinded the data and reset the control. Should have known it was something simple.
Paging not working in Report Viewer
-
12-06-2023 - |
Question
I'm having an issue currently with the Report Viewer control. My current project is an MVC3 app where I link in an aspx page with the Report Viewer control. The page displays, however, I cannot page through the results at all. Here is the code that I have.
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;
}
}
Solution
OTHER TIPS
I encountered same issue a little while back. Add this simple line of code to prevent postback and your pagination issue will be fixed.
if (!IsPostBack){ //enter your report logic here }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow