开发者

CrystalReportViewer problem with navigating between pages

开发者 https://www.devze.com 2022-12-21 14:49 出处:网络
I have an asp.net (2.0) page with a crystal report viewer. I use the following code in the page_load() method

I have an asp.net (2.0) page with a crystal report viewer. I use the following code in the page_load() method

   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");
 开发者_C百科       Session["REP"] = report;
    }
    else
    {
        report = (ReportDocument)Session["REP"];
    }
    rptItems.ReportSource = report;

When I press the 'next page' button on the toolbar of the crystal report viewer, it goes to page 2 as it should and after that it just stays there even if I press the next button again. I tried adding programatically a button which did a .ShowNextPage but that exhibited the same behaviour. What may be the reason?

In case it helps, my crystal report viewer control is declared as below

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


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();
}


i found the solution in other page and... it works! How? Put the code in the page_init() method. This way keeps values when navigate without the isPostBack condition.

Good luck

0

精彩评论

暂无评论...
验证码 换一张
取 消