水晶报告查看器下一页不工作

时间:2014-02-27 06:01:21

标签: asp.net crystal-reports

我正在使用visual studio 2010和crystal report 13.0

报告查看器正确显示第一页。但下一页按钮不起作用。如果我点击下一页按钮然后它会显示加载消息并且只保留在那里。没有任何报告查看器控件正在工作。

请帮帮我

4 个答案:

答案 0 :(得分:6)

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

连接起来

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

答案 1 :(得分:1)

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

自动定义:

SELECT FileName=reverse(left(reverse('\\PRODSERVER\D$\EXPORT\Data20160401.txt'), 

                    charindex('\',reverse('\\PRODSERVER\D$\EXPORT\Data20160401.txt'), 

                             1) - 1))

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

在ASPX中:

    // 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.CS中:

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

答案 2 :(得分:0)

  

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

enter image description here

答案 3 :(得分:0)

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