locked
Crystal Report runs query multiple times on page change RRS feed

  • Question

  • User1243880387 posted

    I have written the code for crystal report in the page_init() and it runs fine, but I have just noticed that when I switch report page index, means when I want to load second page of the report, the control again goes to the page load and whole report query runs again.

    I have made a switch case and from query string I take the name which report is to be loaded, is there a way by which when I can minimize the report load time?

    Is session a better idea?

    If I write the code in (!Ispostaback), then only first page is loaded, when I try to switch second page, it shows no resource is available error.

    protected void Page_Init(object sender, EventArgs e)
        {
            try
            {
                String test = Request.QueryString["ReportType"];
                ReportDocument report = new ReportDocument();
                switch (testCondition)
                {
                       case "Report":
                        var rpt1 = new LenderCompanyActionReport();
                        String lcarParam1 = Request.QueryString["Param1"];
                        String lcarParam2 = Request.QueryString["Param2"];
                        String lcarParam3 = Request.QueryString["Param3"];
                        String lcarParam4 = Request.QueryString["Param4"];
                        String lcarParam5 = Request.QueryString["Param5"];
                        List<Reportclass> lst2 = new ReportMethod().GetReport(lcarParam1, lcarParam2, lcarParam3, lcarParam4, lcarParam5);
                        rpt1.SetDataSource(lst2);
                        CRReportViewer.ReportSource = rpt1;
                        break;
    }

    Friday, May 24, 2013 2:53 AM

Answers

  • User-578610739 posted

    Hi Itityagi,

    It is true to give everytime page_load or page_init happened.

    Actually while Paging click, It actually needed the data source which we given at the first bind. And report automatically done paging inside and give output.

    So in postback it will not assign again and not result comes.

    Better is, make one function and call in pageload , but put outside from ispostback .

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 27, 2013 4:41 AM