代碼
1 #region public static
2 /// <summary>
3 /// 獲取指定ReportViewer總物理頁數
4 /// guog2009-05-06新增
5 /// </summary>
6 /// <param name="reportViewer">ReportViewer控件</param>
7 /// <returns>總物理頁數,默認值為0</returns>
8 public static int GetTotalPage(ReportViewer reportViewer)
9 {
10 int result = 0;
11 //設置為打印預覽模式
12 reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
13
14 //記錄當前頁
15 int currentPage = reportViewer.CurrentPage;
16 if (reportViewer.LocalReport.GetTotalPages() > 0)
17 {//自帶的GetTotalPages()方法返回的是邏輯頁面總數,所以這裡重新處理
18
19 while (true)
20 {
21 try
22 {
23 reportViewer.CurrentPage += 1;
24 }
25 catch
26 {
27 reportViewer.CurrentPage -= 1;
28 result = reportViewer.CurrentPage;
29 break;
30 }
31 finally
32 {
33 //指定到原始位置
34 reportViewer.CurrentPage =<