简体   繁体   English

reportviewer.LocalReport.GetTotalPages()返回0或错误

[英]reportviewer.LocalReport.GetTotalPages() returns 0 or error

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.. 我也想为其创建自定义导航,但是由于某种原因,当我要检查页面总数以决定是否显示导航按钮时,它要么返回0,要么返回“此表达式会产生副作用,因此将不进行评估”错误..

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). 这一切都在我的用户控件(.ascx)中的databind事件上。 Any help is more than appreciated. 任何帮助都超过了赞赏。

This msdn question is probably your answer, the GetTotalPages() method can't be called until after the report has rendered. 这个msdn问题可能是您的答案,在报表呈现后才能调用GetTotalPages()方法。 The relevant quote: 相关报价:

The report server won't calculate the total page count until rendering the first page of the report. 报表服务器在呈现报表的第一页之前不会计算总页数。 The ReportViewer doesn't request a page rendering from the server until the ASP.Net event PreRender. 在ASP.Net事件PreRender之前,ReportViewer不会从服务器请求页面呈现。 If you move the GetTotalPages call to a point after the ReportViewer.PreRender event has fired, you should get the behavior you want. 如果将GetTotalPages调用移至ReportViewer.PreRender事件触发后的某个点,则应获得所需的行为。

See also the ASP.NET Page Lifecycle for reference. 另请参见ASP.NET页面生命周期以供参考。

to get the pages as for me, I had to render the report in pdf, then using pdfreader class from Itextsharp library to get total pages 为了获得与我一样的页面,我不得不以pdf格式呈现报告,然后使用Itextsharp库中的pdfreader类获取总页面

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

this works well if you want to render your rdlc in pdf format 如果您想以pdf格式呈现rdlc,则此方法效果很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 reportviewer.LocalReport.GetTotalPages()有时返回1或2 - reportviewer.LocalReport.GetTotalPages() returns sometimes 1 or 2 在winform的ReportViewer的LocalReport中导出为CSV - Export to CSV in LocalReport of ReportViewer of winform 在本地报表中运行多个数据集的ReportViewer - ReportViewer with multiple dataset running in localreport 以黑白PDF格式从Reportviewer渲染LocalReport - Render LocalReport from Reportviewer in Black and White PDF ASP.NET ReportViewer表达式返回错误 - ASP.NET ReportViewer Expression returns error Visual Studio中devexpress的ReportViewer控件无法识别LocalReport属性 - ReportViewer control of devexpress in visual studio that does not recognize the LocalReport property 从Microsoft.ReportViewer.LocalReport中导出PDF导出中的条形码 - Rendering barcodes in PDF export from Microsoft.ReportViewer.LocalReport 在ASP.NET ReportViewer控件中使用远程SSRS数据源运行LocalReport - Running a LocalReport with a remote SSRS DataSource in ASP.NET ReportViewer control ReportViewer.LocalReport.Refresh和ReportViewer.RefreshData有什么区别? - What's the difference between ReportViewer.LocalReport.Refresh and ReportViewer.RefreshData? LocalReport-渲染Excel返回0长度字节数组 - LocalReport - Render Excel returns 0-length byte array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM