Click here to Skip to main content
Licence CPOL
First Posted 10 Dec 2007
Views 18,261
Downloads 275
Bookmarked 13 times

How to do paging and navigation with Crystal Reports using C# .NET

By | 10 Dec 2007 | Article
Crystal Reports with paging and navigation functionality with C# .NET.

Introduction

This article will help you to learn how to bind a Crystal Reports file with the Crystal Reports Viewer and display it in a Web Page using very simple steps.

Using the code

The code is very simple. Follow the steps below or download the attached file. Create a report in your project under the Reports folder to try this out.

  1. Reference these namespaces:
  2. using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
  3. Declare a private report object in your main class:
  4. private ReportDocument reportDocument;
  5. Implement the Page_Init method in your web page with the following code:
  6. private void Page_Init(object sender, EventArgs e)
    {
        reportDocument = (ReportDocument)Session["reportDocument"];
        crystalReportViewer.ReportSource = reportDocument;
    }
  7. The method below will set the default logon information to the CrystalReportViewer:
  8. public void setLogonInfo()
    {
        //--------------------
    
        TableLogOnInfo logOnInfo = new TableLogOnInfo();
        //logOnInfo = oRpt.Database.Tables["Customers"].LogOnInfo;
    
        logOnInfo.ConnectionInfo.ServerName = "srvr";
        logOnInfo.ConnectionInfo.DatabaseName = "database";
        logOnInfo.ConnectionInfo.UserID = "sa";
        logOnInfo.ConnectionInfo.Password = "pwd";
        //logOnInfo.TableName = "table";
    
        TableLogOnInfos infos = new TableLogOnInfos();
        infos.Add(logOnInfo);
        crystalReportViewer.LogOnInfo = infos;
    }
  9. Implement the code below for the button click event:
  10. protected void display_Click(object sender, EventArgs e)
    {
        reportDocument = new ReportDocument();
        reportDocument.Load("C:\\myExample\\Reports\\OnlineTest.rpt");
        //reportDocument.Load(reportsList.SelectedValue);
    
        Session["reportDocument"] = reportDocument;
        crystalReportViewer.ReportSource = reportDocument;
        setLogonInfo();
    }

    [Optional step]

  11. The code below can be used to retrieve conditional data through the CrystalReportViewer. This can be written wherever you want to implement it. Let's say, by clicking on Search By Employee Id, you want to display some employee data in the ReportViewer and print it:
  12. crystalReportViewer.SelectionFormula = 
        "{Table.FieldName}=" + DynamicValue + "";

That's all!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

KennyPatel

Software Developer (Senior)

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Layout  Per page   
  Refresh
QuestionDoes this work when parameters are passed? PinmemberSteve P.2:13 19 Dec '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 11 Dec 2007
Article Copyright 2007 by KennyPatel
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid