C#
  Home arrow C# arrow Page 3 - Crystal Reports for Visual Studio 2005 in ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Crystal Reports for Visual Studio 2005 in CSharp
By: MSDN Virtual Labs
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 64
    2006-02-02

    Table of Contents:
  • Crystal Reports for Visual Studio 2005 in CSharp
  • Exercise 2: Creating a Custom Stock Market Information
  • Exercise 4: Bind your Crystal Report to the Crystal Report Viewer
  • Exercise 5: Adding Data Dynamically to the Stock Report
  • Exercise 6: Adding Charts and Summary Information to the Report

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Crystal Reports for Visual Studio 2005 in CSharp - Exercise 4: Bind your Crystal Report to the Crystal Report Viewer


    (Page 3 of 5 )

    Scenario

    In this exercise, you will bind the Stock Objects report to the Crystal Report Viewer, set the data source of the report to an Object Collection, and populate the Object Collection programmatically.

            Tasks              Detailed Steps

    1. Binding the Report to the Crystal Report Viewer.

      1. Switch to the default Code-Behind class, Default.aspx.cs.
      2. Above the class signature, add a "using" declaration to the top of the class for the System.Collections namespace.

        using System.Collections;

        This reference gives you access to the ArrayList class. ArrayList implements ICollection. This qualifies ArrayList as one of several class types that can be used to build an object collection that is recognized by Crystal Reports.
      3. Add a new class-level ArrayList, call it stockValues.

        private ArrayList stockValues;
      4. Add a new class-level declaration for the ReportDocument report wrapper class, with the variable name stockObjectsReport. Set its access modifier to private.

        private ReportDocument StockObjectsReport;
      5. Within the ConfigureCrystalReports()method you created in Exercise 1: Web Application Setup, declare a string variable, name it reportPath, and assign to it a runtime path to the local report. Pass the name of the local report file as a string parameter into the Server.MapPath() method. This maps the local report to the file path at runtime.

        String reportPath = Server.MapPath("StockObjects.rpt");

      6. Add two line breaks, and instantiate the ReportDocument class.

        StockObjectsReport = new ReportDocument(); 
      7. On the next line, Call the Load()method of the ReportDocument instance and pass into it the reportPath string variable.

        StockObjectsReport.Load(reportPath);

        The ReportDocument class is a member of the CrystalDecisions.CrystalReports.Engine namespace. You have added a "using" [C#] declaration for this namespace in Exercise 1: Web Application Setup. When you instantiate ReportDocument and load a report, you gain access to the report through the SDK.
      8. Next, set the data source of the report to the stockValues ArrayList.

        StockObjectsReport.SetDataSource(stockValues);
      9. Finally, bind the ReportSource property of the CrystalReportViewer to the ReportDocument instance.

        crystalReportViewer.ReportSource = stockObjectsReport;

        At this point, the Stock Objects report is bound to the Crystal Report Viewer and the page displays the correct report; however, the report is currently bound to an empty data source, thus the report has no information to display. In the next step, you will programmatically populate the stockValues ArrayList with sample data.

    2. Populating the Object Collection Programmatically.

      In this task, you will add Session code to the ASPX code-behind class. If there are no values currently held in session, default values will be created. If there are values in session, they will be assigned to the stockValues ArrayList.

      1. Within the class, add a new public scope helper method, with no return value, named PopulateStockValuesArrayList().

        public void PopulateStockValuesArrayList()
        {
        }

      2. Within the PopulateStockValuesArrayList()method, before the existing code, create an if/else conditional block that checks whether a Session object named stockValues exists.

        if(Session["stockValues"] == null)
        {
        }
        else
        {
        }

      3. Within the If block, instantiate a new ArrayList().

        stockValues = new ArrayList();
      4. Next, use the overloaded constructor for the Stock class to create and instantiate three instances of Stock.

        Stock s1 = new Stock("AWRK",1200,28.47);
        Stock s2 = new Stock("CTSO",800,128.69);
        Stock s3 = new Stock("LTWR",1800,12.95);

      5. Add these three instances to stockValues.

        stockValues.Add(s1); stockValues.Add(s2); stockValues.Add(s3);
      6. Add the updated stockValues ArrayList into session.

        Session["stockValues"]=stockValues;
      7. Inside of the Else block, write a line to assign the current values held in session to the stockValues ArrayList.

        stockValues = (ArrayList)Session["stockValues"];

      8. Finally, call the PopulateStockValuesArrayList() from the ConfigureCrystalReports()method.
      9. This should be the first line of code executed in the ConfigureCrystalReports() method.

        PopulateStockValuesArrayList();

      10. From the Build menu, click Build Solution.

        If you have any build errors, fix them now.
      11. From the Debug menu, click Start Debugging.
      12. If this is the first time you have started debugging, a dialog box appears and states that the Web.config file must be modified. Click the OK button to enable debugging.

        The Default.aspx page loads into your browser with three default values.
      13. Close the Internet Explorer window.

    Take Microsoft software for a test drive. With MSDN Virtual Labs, you get full access to all available Microsoft products through 90-minute modules, each with its own downloadable manual. Try this lab out now.

    More C# Articles
    More By MSDN Virtual Labs


       · We hope you found this article by MSDN Virtual Labs to be enjoyable and educational....
       · This exercise has been followed to the letter and cannot run. It opens with a...
       · hiim very new to asp.net here ..i encountered this msg, No overload for method...
       · I have the same problem too. Answer?
       · I also have this problem. It seems to me that if the report use dataset and/or .net...
       · CAN YOU POST THE STEP BY STEP EXAM FOR WINFORM APPLICATION ? THANK YOU VERY...
       · I encountered the same problem .. pls let me know how to disable the login prompt...
       · This is the best ever tutorial article I ever seen on the net
       · Hi,I think you have put following methods in wrong...
     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT