YH to solve the problem of turning page of Crystal Report perfectly

Source: Internet
Author: User

An error has been encountered during maintenance YH: The report query has 4 pages of data, the default display of the first page, click on the next page, display Normal, and then click on the next page, should have shown the third page, the result is displayed on the second page, click the last and home can be normal display, enter the page number, click the Jump button can also be normal display. Very strange problem, but have to solve, the customer there are requirements. Kung Fu not negative, after the "arduous" finally resolved.

To reach the party, the solution is of course the most want to see first, then let's talk about my solution:

"Solution"

Source:

protected void Page_Load (object sender, EventArgs e)  
 {  
     if (session["Admin"] = = null)  
     {  
         Page.ClientScript.RegisterStartupScript (Page.gettype (), "message", "<script language= ' JavaScript ' defer> Alert (' Your session time has expired, please login again! ');</script> ");  
         Response.Write ("<script language=javascript>window.top.location.href="). /login.aspx ' </script> ');  
         return;  
     }  
Query the report and display (query by time period)  
checkbetweentime ();  
 }

Modified code:

protected void Page_Load (object sender, EventArgs e)  
{  
    if (session["Admin"] = = null)  
    {  
        Page.ClientScript.RegisterStartupScript (Page.gettype (), "message", "<script language= ' JavaScript ' defer> Alert (' Your session time has expired, please login again! ');</script> ");  
        Response.Write ("<script language=javascript>window.top.location.href="). /login.aspx ' </script> ');  
        return;  
    }  
    Query the report and display (query by time period)  
      //checkbetweentime ();  
}

Add code:

protected void Crystalreportviewer1_navigate (object sender, EventArgs e)  
{  
    //query report and display (query by time period)  
       Checkbetweentime ();            
}

The source code changes:

<cr:crystalreportviewer id= "CrystalReportViewer1" runat= "Server" autodatabind= "true" displaygrouptree= "false" onnavigate= "Crystalreportviewer1_navigate"/>

Test again, OK.

Clicking the page on the "parse" MSDN button triggers the Navigate event. Crystalreportviewer Event Member: http://msdn.microsoft.com/zh-cn/library/ms227097 (v=vs.90). aspx

So we simply rebind the data source in the Crystalreportviewer Navigate event, which can fundamentally solve the problem.

It's also a solution, but the solution has limitations: because my data binding is acquired through interface control data, the Page_Init event is a page initialization event, which is said to be a Page_Load data source binding operation in the Page_Init event. At this time the control is not assigned value, so the condition of course is wrong, the condition is wrong, the result is wrong. The Navigate event is done after the Page_Init and Page_Load events are completed, conditions can be obtained normally, and then binding the data source.

Note: Crystalreportviewer all paging operations trigger the Navigate event. We can call Crystalreportviewer's separate paging method:

Crystalreportviewer1.showfirstpage ();     Home  
crystalreportviewer1.showlastpage ();      Last  
crystalreportviewer1.shownextpage ();      Next page  
crystalreportviewer1.showpreviouspage ();  Previous page  
crystalreportviewer1.shownthpage (N);      Jump to Nth page

With these methods, just rewrite the methods and combine the navigate events to achieve the desired functionality.

Author: csdn Blog Trichengrong

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/tools/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.