Crystal Reports for Visual Studio 2005 in CSharp (Page 1 of 5 ) This article, written by MSDN Virtual Labs, guides you through the creation of a Crystal Reports web application that reports off of data from an Object Collection. You will create a unique class to hold stock market values, instantiate the class, and more. Objectives After completing this lab, you will be better able to: Create a unique class to hold stock market values.
Instantiate the class.
Populate and object collection with data.
Dynamically add data through a web form.
- Create a crystal report with the Crystal Report Designer.
Scenario This lab guides you through the creation of a Crystal Reports web application that reports off of data from an Object Collection. The application is developed with Crystal Reports for Visual Studio 2005 Beta 2.
Then you will create a unique class to hold stock market values, instantiates the class and populates an object collection with data, and dynamically adds further data through a web form. You will then create a Crystal report with the Crystal Report Designer control that connects to the object collection and dynamically generates a chart and stock summary
Estimated Time to Complete This Lab 60 Minutes
Exercise 1: Web Application Setup Scenario In this exercise, you will create a new Web Site and apply the standard settings needed to complete the lab. Tasks Detailed Steps
Create the Web site in this section you will create a new ASP.NET Web Site in Visual Studio.
Double-click the Visual Studio 2005 Beta 2 shortcut on the desktop. Click File | New | Web Site. In the New Web Site dialog box, click ASP.NET Web Site. In the Location list, select File System. In the Language list, select Visual C#. In the Location text field, accept the default path and name.
Adding the Crystal Report Viewer Control. From the Solution Explorer, double click Default.aspx to open the web form. Click the Design button at the bottom of the form to change the Web Form to Design view. From the Toolbox, expand the Crystal Reports node and locate the CrystalReportViewer control. Drag the CrystalReportViewer control onto the Web Form. If the Smart Task panel CrystalReportViewer Tasks is open, press Esc on your keyboard to close it.
The Smart Task panel is a new feature to Visual Studio 2005 that allows for a reduced code approach to creating projects. In this lab, you will use a programmatic approach, and thus will not use the Smart Task panel. Click the Properties tab and select the CrystalReportViewer. From the Properties window, set the ID property to crystalReportViewer. From the File menu, click SaveAll.
Adding the Programmatic Settings. Click the Solution Explorer tab. In the Solution Explorer, right click Default.aspx and click View Code. Above the class signature, add a "using" declaration for the namespaces of the assemblies that are listed below.
using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; Within the class, add a new private scope helper method, with no return value, named ConfigureCrystalReports().
private void ConfigureCrystalReports() { }
ConfigureCrystalReports() is a helper method that interacts with the report at runtime. It also controls programmatic interaction with the report. In order to correctly configure the CrystalReportViewer, it must be called from Page_Init(). Add the Page_Init event handler. Use the exact syntax shown.
private void Page_Init(object sender, EventArgs e) { }
In a C# Web form in Visual Studio 2005, the Page_Init event handler in the code-behind class is automatically wired to the Init event. The event handler signature must match exactly in order to be called. Finally, within the Page_Init event handler, enter a call to the ConfigureCrystalReports() helper method.
ConfigureCrystalReports(); From the File menu, click Save All.
You are now ready to create your custom stock market information class.
 | 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. |
Next: Exercise 2: Creating a Custom Stock Market Information >>
More C# Articles More By MSDN Virtual Labs |