2010-03-03 88 views
2

我有一个带有水晶报表查看器的asp.net(2.0)页面。我用下面的代码在Page_Load()方法CrystalReportViewer页面间导航问题

if (!Page.IsPostBack) 
    { 
     Session["REP"] = null; 
    } 
    ReportDocument report; 
    if (Session["REP"] == null) 
    { 
     report = new ReportDocument(); 
     report.Load(Server.MapPath("reports\\rptListItems.rpt")); 
     report.SetDatabaseLogon(Session["DB_USER"].ToString(), 
           Session["DB_PWD"].ToString(), 
           Session["DB_ODBC"].ToString(), "DBNAME"); 
     Session["REP"] = report; 
    } 
    else 
    { 
     report = (ReportDocument)Session["REP"]; 
    } 
    rptItems.ReportSource = report; 

当我按下水晶报表浏览器的工具栏上的“下一页”按钮,就因为它应该进入到第2页之后,它只是停留即使我再次按下下一个按钮。我试图通过编程添加一个.ShowNextPage按钮,但展现出相同的行为。可能是什么原因?

万一有帮助,我的水晶报表查看器控件的声明如下

<CR:CrystalReportViewer ID="rptItems" runat="server" AutoDataBind="true" 
      EnableDatabaseLogonPrompt="False" 
      EnableParameterPrompt="False" Height="50px" 
      ReuseParameterValuesOnRefresh="True" Width="800px" 
      DisplayGroupTree="False" 
      HasCrystalLogo="False" /> 

回答

0

我发现在其他页面的解决方案,...它的作品!怎么样?将代码放入page_init()方法中。这种方式保持不导致isPostBack条件时的值。

祝你好运

1
protected void Page_Load(object sender, EventArgs e) 
{ 
    if (Session["UID"].ToString() == "0" || Session["UID"].ToString() == "" && Session["CID"].ToString() == "0" || Session["CID"].ToString() == "") 
    { 
     Response.Redirect("Login.aspx"); 
    } 
    else 
     Response.Cache.SetExpires(DateTime.Now.AddDays(-1)); 
    Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    if (IsPostBack) 
    { 
     lblStatus.Text = ""; 
     function(); 
    } 
} 
protected void Page_UnLoad(object sender, EventArgs e) 
{ 
    ReportDocument crystalReport = new ReportDocument(); 
    this.CrystalReportViewer1.Dispose(); 
    this.CrystalReportViewer1 = null; 
    crystalReport.Close(); 
    crystalReport.Dispose(); 
    GC.Collect(); 
}