1

I'm using a user control, and added my report viewer and a custom toolbar. I want to create a custom navigation for it aswell, but for some reason when I want to check the total pages to decide whether or not to show the navigation buttons it either returns 0 or "This expression causes side effects and will not be evaluated" error..

I've ran out of ideas and not quite sure where to go from here..

<rsweb:reportviewer 
ID="rvReports" 
runat="server" ShowToolBar="False"
SizeToReportContent="True" AsyncRendering="false" />

codebehind:

rds = new Microsoft.Reporting.WebForms.ReportDataSource("dsName", myclasstoload());     
rvReports.LocalReport.DataSources.Add(rds);
rvReports.PageCountMode = PageCountMode.Actual;
rvReports.LocalReport.Refresh();
rvReports.DataBind();


if (rvReports.LocalReport.GetTotalPages() > 1)
{
 liFirst.Visible = true;
 liPrevious.Visible = true;
 liNext.Visible = true;
 liLast.Visible = true;
}

this is all on the databind event in my usercontrol (.ascx). Any help is more than appreciated.

4

2 回答 2

1

这个msdn question可能是您的答案,GetTotalPages()直到报告呈现后才能调用该方法。相关报价:

在呈现报表的第一页之前,报表服务器不会计算总页数。在 ASP.Net 事件 PreRender 之前,ReportViewer 不会从服务器请求页面呈现。如果在 ReportViewer.PreRender 事件触发后将 GetTotalPages 调用移动到某个点,您应该会获得所需的行为。

另请参阅ASP.NET 页面生命周期以供参考。

于 2012-07-12T08:01:31.437 回答
0

为了像我一样获取页面,我必须以 pdf 格式呈现报告,然后使用 Itextsharp 库中的 pdfreader 类来获取总页数

var bytes=viewer.Render("PDF");
PdfReader reader = new PdfReader(bytes);
var pageCount = reader.NumberOfPages

如果您想以 pdf 格式呈现您的 rdlc,这很有效

于 2018-02-16T19:57:28.923 回答