Code
1 # region public static
2 /// <summary>
3 // obtain the total number of physical pages of the specified ReportViewer
4 // new guog2009-05-06
5 /// </summary>
6 /// <param name = "reportViewer"> ReportViewer Control </param>
7 // <returns> total number of physical pages. The default value is 0. </returns>
8 public static int GetTotalPage (ReportViewer reportViewer)
9 {
10 int result = 0;
11 // set to print preview mode
12 reportViewer. SetDisplayMode (DisplayMode. PrintLayout );
13
14 // record the current page
15 int currentPage = reportViewer. CurrentPage;
16 if (reportViewer. LocalReport. GetTotalPages ()> 0)
17 {// the built-in GetTotalPages () method returns the total number of logical pages.
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 // specify the original location
34 reportViewer. CurrentPage = <