【200分 解决马上结贴】ReportViewer获取报表总页数GetTotalPages为0是神马情况?!
这是按钮的Click事件:
protected void Button1_Click(object sender, System.EventArgs e) { GetReport();//给报表绑定数据 lblCount.Text = ReportViewer1.LocalReport.GetTotalPages().ToString();//获取报表总页数 txtPage.Text = ReportViewer1.CurrentPage.ToString();//当前页 }
lblCount.Text = ReportViewer1.LocalReport.GetTotalPages().ToString(); txtPage.Text = ReportViewer1.CurrentPage.ToString();
//方法一:StatusBar bar = crystalReportViewer1.Controls[4] as StatusBar; string[] s = bar.Panels[1].Text.Split(':'); int total = Convert.ToInt32(s[1]);//方法二:ReportDocument rptDocument = (ReportDocument)crystalReportViewer1.ReportSource; CrystalDecisions.Shared.ReportPageRequestContext rprc = new CrystalDecisions.Shared.ReportPageRequestContext(); int totalPCount = rptDocument.FormatEngine.GetLastPageNumber(rprc);
[解决办法]
你肯定帮顶成功了么 ?确认所有的数据都在么 ?数据验证过么
[解决办法]
protected void Button1_Click(object sender, EventArgs e) { SqlConnection myConn = new SqlConnection("Data Source=192.168.0.36;Initial Catalog=Northwind;User ID=sa;Password=sa"); SqlDataAdapter myda = new SqlDataAdapter("Sales by Year", myConn); myda.SelectCommand.Parameters.AddWithValue("@Beginning_Date", "1997-10-10"); myda.SelectCommand.Parameters.AddWithValue("@Ending_Date", "2000-10-10"); myda.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet myds = new DataSet(); myConn.Open(); myda.Fill(myds); myConn.Close(); ReportViewer1.Visible = true; ReportDataSource rds = new ReportDataSource("DataSet1_Sales_by_Year", myds.Tables[0]); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh(); }
[解决办法]
txtPage.Text = ReportViewer1.CurrentPage.ToString();//当前页
之后还有些什么吗 ?
if(!IsPostBack)
有木有 。
[解决办法]
听说绑定也有份拿!
[解决办法]
DataTable dt = GetData(); ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh();
[解决办法]
你不是说:如果点一下ReportViewer的刷新就可以正常的获取到了。
如果这里的刷新可以,ReportViewer1.LocalReport.Refresh();一下,应该也可以。
protected void Button1_Click(object sender, System.EventArgs e) { GetReport();//给报表绑定数据 ReportViewer1.LocalReport.Refresh();//刷新一下数据源控件,再获取呢。 lblCount.Text = ReportViewer1.LocalReport.GetTotalPages().ToString();//获取报表总页数 txtPage.Text = ReportViewer1.CurrentPage.ToString();//当前页 }
[解决办法]
MSDN
当报表在正常模式下显示时(DisplayMode 为 Normal),此方法返回与 LocalReport 或 ServerReport 中的 GetTotalPages 相同的值,具体取决于 ProcessingMode 的当前值。当报表在打印布局模式下显示时(DisplayMode 为 PrintLayout)),此方法返回当前已生成的页面总数。如果报表页仍在生成(尚未触发 RenderingComplete 事件),则生成更多页时此值将更新。
protected void Button1_Click(object sender, System.EventArgs e){ GetReport();//给报表绑定数据 lblCount.Text = ReportViewer1.LocalReport.GetTotalPages().ToString();//获取报表总页数 ReportViewer1.RenderingComplete += new EventHandler(GetTotalPages);}private GetTotalPages(object sender, RenderingCompleteEventArgs e){ lblCount.Text = ReportViewer1.LocalReport.GetTotalPages().ToString();//获取报表总页数}
[解决办法]
掉了个void
[解决办法]
还是贴贴代码吧,把打开页面到最后绑定下来的代码贴出来看看,帮顶下
[解决办法]