代码之家  ›  专栏  ›  技术社区  ›  Ryan

Crystal Reports Viewer不会超过第2页

  •  15
  • Ryan  · 技术社区  · 16 年前

    我在一个aspx页面上有一个crystalreportviewer控件,它应该有内置的分页功能。

    当我第一次单击“下一页”按钮时,我会从第1页移到第2页,但每隔一次单击“下一页”时,报告将重新加载到第2页。

    10 回复  |  直到 16 年前
        1
  •  24
  •   Ryan    16 年前

    问题可能源于设置Crystal Report Viewer控件的 ReportSource Page_Load 事件。这会导致页面信息在每次页面加载时被重写,因此“当前页面”在应该为2时被重新设置为1。

    报告来源 Page_Init

        2
  •  5
  •   Damodaran    12 年前

    手动添加Page\u Init()事件,并使用将其连接到InitializeComponent()中

    this.Init += new System.EventHandler(this.Page_Init).
    

    Page_Load Page_Init() .

    if (!IsPostBack) PageInIt中的条件。

    protected void Page_Init(object sender, EventArgs e) {
    
        if (!IsPostBack)
        {
             ReportDocument crystalReportDocument = new ReportDocumment();
             crystalReportDocument.SetDataSource(DataTableHere);
             _reportViewer.ReportSource = crystalReportDocument;
             Session["ReportDocument"] = crystalReportDocument;
        }
        else
        {
              ReportDocument doc = (ReportDocument)Session["ReportDocument"];
              _reportViewer.ReportSource = doc;
        }
    }
    
        3
  •  4
  •   Konrad Viltersten    13 年前
    if (!Page.IsPostBack)
    {
      //Write your Report display code 
    
      crystalRep.Load(Server.MapPath("DueFD.rpt"));
      crystalRep.SetDatabaseLogon(DB_UId, DB_Pass, Serv_Name, DB_Name);
      CrystalReportViewer1.ReportSource = crystalRep;
    
      // session code
      ReportDocument doc = (ReportDocument)Session["ReportDocument"];
      CrystalReportViewer1.ReportSource = doc;
    }
    else
    {
      ReportDocument doc = (ReportDocument)Session["ReportDocument"];
      CrystalReportViewer1.ReportSource = doc;
    }
    
        4
  •  1
  •   Khaled Eltabei    10 年前

    页面加载

        5
  •  1
  •   Karthick Jayaraman    10 年前

    对我有用!!

    ReportDocument rd = new ReportDocument();
    
            protected void Page_Load(object sender, EventArgs e)
            {           
                string rptpath = WebConfigurationManager.AppSettings["ReportPath"].Replace("{TID}", Convert.ToString(Session["TID"]));
                rd.Load(rptpath);
    
                DataTable dtable = TemplateModel.LoadChequeData(Convert.ToString(Session["CID"]));
                rd.SetDataSource(dtable);           
            }
    
            protected void Page_Init(object sender, EventArgs e)
            {
                CrystalReportViewer1.ReportSource = rd;
            }
    
        6
  •  0
  •   lausite    16 年前

    我以前在visualstudio2008上遇到过这个问题,

        7
  •  0
  •   eternal    15 年前

        8
  •  0
  •   Anh Nguyen    11 年前

    我把所有的加载报告放在Page_Init而不是Page_Load中。而且工作正常。

        9
  •  0
  •   Serghei T    9 年前

    我有一些方法可以分享。我开发了一个简单的CR包装器,可以帮助呈现Crystal报告。按原样使用此代码。请随意修改,扩展代码的任何部分。 下载链接 https://1drv.ms/u/s!AlTLBrnU_bLUiaoUxcxNiRCZRQjWng

    以及如何使用CR包装器类的示例 enter code here 实现IDisposable接口。在Page_Init中设置报表源,在Page_Load事件中设置报表参数,在Page_Unload事件中释放报表文档。
    第二个方法使用静态类,在一个实例中呈现报表,最后处理报表文档。报告源应保存到会话变量中。请注意,第二种方法并不适合高流量的web应用程序,因为使用静态类。如果两个用户同时运行任何报表,则会发生冲突。

    using System;
    using System.Linq;
    using CrystalDecisions.Shared;
    using System.Configuration;
    using System.Web.Configuration;
    using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper
    
    
    namespace YourNamespace
    {
        public partial class ReportForm : System.Web.UI.Page
        {
    
            protected string _serverName;
            protected string _databaseName;
            protected string _schemaName;
            protected string _userId;
            protected string _userPassword;
            protected bool _integratedSecurity;
            protected string _databaseType;
            //Wrapper Report Document
            protected CReportDocument _reportDocument;
    
            /// <summary>
            /// Load report
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Page_Init(object sender, EventArgs e)
            {
                //Wrapper object
                this._reportDocument = new CReportDocument();
    
                //These settings should be initialized from i.e. web.config in Page_PreInit
    
                this._reportDocument.ServerName = this._serverName;
                this._reportDocument.DatabaseName = String.Empty;
                this._reportDocument.SchemaName = this._schemaName;
                this._reportDocument.DatabaseType = CReportDatabaseType.ORACLE;
                this._reportDocument.UserId = this._userId;
                this._reportDocument.UserPassword = this._userPassword;
                this._reportDocument.IntegratedSecurity = false;
    
    
                //Get report name from query string. Define Your own method to get report name
                var parReportName = Request.QueryString["reportname"];
    
                if (String.IsNullOrEmpty(parReportName))
                {
                    lblConfigError.Text = "Crystal Report name is not being provided.";
                    return;
                }
    
                //Set Report file
                this._reportDocument.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName;
                //Set Report documant
                this._reportDocument.SetReportDocument();
                //Get Report Document
                crViewer.ReportSource = this._reportDocument.GetReportDocument();
    
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
                CReportParameter reportParameter;
    
                //Get parameters Your own method to provide report parameters
                var parFimYear = RouteData.Values["par1"];
                var parFimCityCode = RouteData.Values["par2"];
    
                if (par1 == null || par2 == null)
                {
                    lblConfigError.Text = "Crystal Report parameters are not being provided.";
                    return;
                }
    
                //Define Report Parameter
                reportParameter = new CReportParameter();
                reportParameter.ParameterName = "@parYear";
                reportParameter.ParameterValue = parFimYear;
                reportParameter.crParameterValueKind = ParameterValueKind.StringParameter;
                _reportDocument.AddCReportParameter(reportParameter);
    
                reportParameter = new CReportParameter();
                reportParameter.ParameterName = "@parCityCode";
                reportParameter.ParameterValue = parFimCityCode;
                reportParameter.crParameterValueKind = ParameterValueKind.StringParameter;
                _reportDocument.AddCReportParameter(reportParameter);
    
                //Set report parameters
                this._reportDocument.SetReportParameters();
    
            }
    
            protected void Page_Unload(object sender, EventArgs e)
            {
                this._reportDocument.Dispose();
            }
    
        }
    }
    

    方法2

    using System;
    using System.Linq;
    using CrystalDecisions.Shared;
    using System.Configuration;
    using System.Web.Configuration;
    using CrystalDecisions.CrystalReports.Engine;
    using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper
    
    namespace YourNamespace
    {
        public partial class ReportForm : System.Web.UI.Page
        {
    
            protected string _serverName;
            protected string _databaseName;
            protected string _schemaName;
            protected string _userId;
            protected string _userPassword;
            protected bool _integratedSecurity;
            protected string _databaseType;
    
            /// <summary>
            /// Load report
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Page_Init(object sender, EventArgs e)
            {
                CReportParameter reportParameter;
    
                //These settings should be initialized from i.e. web.config in Page_PreInit
    
                if (!IsPostBack)
                {
                    if (this._databaseType == CReportDatabaseType.ORACLE.ToString())
                    {
                        //static wrapper class
                        CReportDocumentManager.ServerName = this._serverName;
                        CReportDocumentManager.DatabaseName = String.Empty;
                        CReportDocumentManager.SchemaName = this._schemaName;
                        CReportDocumentManager.DatabaseType = CReportDatabaseType.ORACLE;
                        CReportDocumentManager.UserId = this._userId;
                        CReportDocumentManager.UserPassword = this._userPassword;
                        CReportDocumentManager.IntegratedSecurity = false;
    
                        //Get report name from query string. Define Your own method to get report name
                        var parReportName = Request.QueryString["reportname"];
    
                        if (String.IsNullOrEmpty(parReportName))
                        {
                            lblConfigError.Text = "Crystal Report name is not being provided.";
                            return;
                        }
                            //get par1. Your own method to provide report parameters. This is from MVC application
                            var par1 = RouteData.Values["par1"];
                            //get par2
                            var par2 = RouteData.Values["par2"];
    
                            if (par1 == null || par2 == null)
                            {
                                lblConfigError.Text = "Crystal Report parameters are not being provided.";
                                return;
                            }
    
                            reportParameter = new CReportParameter();
                            reportParameter.ParameterName = "@parYear";
                            reportParameter.ParameterValue = par1;
                            reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter;
                            CReportDocumentManager.AddCReportParameter(reportParameter);
    
                            reportParameter = new CReportParameter();
                            reportParameter.ParameterName = "@parCityCode";
                            reportParameter.ParameterValue = par2;
                            reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter;
                            CReportDocumentManager.AddCReportParameter(reportParameter);
    
    
    
                        CReportDocumentManager.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName;
                        ReportDocument doc = CReportDocumentManager.GetCReportDocument();
                        crViewer.ReportSource = doc;
                        Session[parReportName] = doc;
    
                    }
                }
                else
                {
                    var parReportName = Request.QueryString["reportname"];
                    ReportDocument doc = (ReportDocument)Session[parReportName];
                    crViewer.ReportSource = doc;
    
                }                
            }
    
        }
    }
    
        10
  •  0
  •   Paul Nicklin    7 年前

    我已经尝试过上面的解决方案,但是由于我们发回更新报告参数而变得更加复杂,并且如果您不在页面加载时设置报告参数,那么刷新将失败。所以到今天为止,如果没有页面加载,我就无法运行它。

    我怀疑我可能需要添加一些逻辑来检查更改的param值,并且只有在其中一个值发生更改时才刷新报告。

    最后我删除了我们的“侧栏”页面上下链接,并使用了查看器上的链接。我看不出任何办法,因为页面挂钩可以让它工作-