【问题标题】:crystal report viewer next page not working水晶报表查看器下一页不工作
【发布时间】:2014-02-27 06:01:21
【问题描述】:

我正在使用 Visual Studio 2010 和 Crystal Report 13.0

报表查看器正确显示第一页。但是下一页按钮不起作用。如果我单击下一页按钮,则它会显示加载消息并仅停留在那里。所有报告查看器控件都不起作用。

请帮帮我

【问题讨论】:

标签: asp.net crystal-reports


【解决方案1】:

我找到了解决方案。 手动添加 Page_Init() 事件并将其连接到 InitializeCompnent()

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

Page_Load的内容移动到Page_Init()

PageInIt 中添加if (!IsPostBack) 条件。

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

【讨论】:

  • 这是我非常需要的解决方案!谢谢!
【解决方案2】:

您可以将 CrystalReportViewer AutoDataBind 属性与 DataBinding 事件结合使用,而不是手动识别要绑定的时刻。

自动绑定定义:

    // Summary:
    //     Boolean. Gets or sets whether automatic data binding to a report source is
    //     used. If the value is set to True, the DataBind() method is called after
    //     OnInit() or Page_Init().
    [Category("Data")]
    [DefaultValue(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public bool AutoDataBind { get; set; }

您可以通过以下方式使用此属性:

在 ASPX 中:

<CR:CrystalReportViewer ID="_reportViewer" runat="server" AutoDataBind="true" OnDataBinding="_reportViewer_DataBinding" />

在 ASPX.CS 中:

protected void _reportViewer_DataBinding(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;
    }
}

【讨论】:

  • 如果同时查看两份报告,我将如何区分两个不同的报告文件?
  • 要同时查看两个报告,您可能需要两个 ReportViewer 控件。这使您能够定义两个 DataBinding 事件处理程序方法。这些方法有效地使您能够为报告选择正确的数据源。蜘蛛侠使用会话。您可以使用它来存储另一个对象。然而,没有什么能阻止您查询数据存储。
【解决方案3】:

完成!将您的页面加载事件转换为页面初始化事件。

【讨论】:

    【解决方案4】:
     protected void Page_Load(object sender, EventArgs e)
     {
         if (IsPostBack)
         {
               int pageIndex =((CrystalDecisions.Shared.PageRequestContext)  
                CrystalReportViewer1.RequestContext).PageNumber;
    
               //Bind Report with filter and datasource
    
               string ControID = GetPostBackControlName(this);
              //get and check Crystal Report Navigation button event after Bind Report
    
               if (ControID == null)
               {  
                  ((CrystalDecisions.Shared.PageRequestContext)
                  CrystalReportViewer1.RequestContext).PageNumber = pageIndex;      
                }
          }
     }
    
     public string GetPostBackControlName(Page Page)
        {
            Control control = null;
    
            string ctrlname = Page.Request.Params["__EVENTTARGET"];
            if (ctrlname != null && ctrlname != String.Empty)
            {
                control = Page.FindControl(ctrlname);
            }
            else
            {
                string ctrlStr = String.Empty;
                Control c = null;
                foreach (string ctl in Page.Request.Form)
                {
                    if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
                    {
                        ctrlStr = ctl.Substring(0, ctl.Length - 2);
                        c = Page.FindControl(ctrlStr);
                    }
                    else
                    {
                        c = Page.FindControl(ctl);
                    }
                    if (c is System.Web.UI.WebControls.Button ||
                             c is System.Web.UI.WebControls.ImageButton)
                    {
                        control = c;
                        break;
                    }
                }
            }
            if (control == null)
            {
                return null;
            }
            else
            {
                return control.ID;
            }
        }
    

    【讨论】:

    • 欢迎来到 Stack Overflow!这是一个仅代码的答案,在 SO 中不被认为是好的质量。请添加解释并详细说明此代码的作用以及它有助于解决问题的原因。
    • 即使是Page_Load,在报表绑定后会将水晶报表页面索引重置为1,我们必须在导航时绑定报表前后维护它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 2017-08-21
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多