You are on page 1of 11

Crystal Reports and ASP.NET 2.

Building a Web Reports Interface

Crystal Reports Web Interface


What is a Reports Interface? A set of ASP.NET Web pages designed to organize and present an unlimited collection of Crystal Reports. Information about each report is stored in SQL 2000 reportid, reporttitle, reportfile, reportcategory. Features 1.Reports listed in simple grid-like format 2.Users can pick reports based on multiple categories 3.Single driver page used to launch reports in CrystalReportsViewer Advantages 1.Easy to deploy reports throughout the organization -reports become immediately available once copied to repository 2.Ease of maintenance (database driven) -reports and categories can be added, deleted, renamed -no special coding. 3.Cost-effective 4.No special software browser-based 5.Uses standard Microsoft tools (VS2005

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

New Features in ASP.NET 2.0


Crystal Reports project templates (ASP.NET Crystal Reports Website) Visual Studio 2005 has Crystal Report project templates for Visual Basic, C#, and J# Web Sites. The project templates create a default Crystal Reports project and start the New Report Creation Wizard to help new users create reports. Smart Tags In Visual Studio 2005, when you add a .NET control to a Web Form, a Smart Tag panel appears. The CrystalReportViewer Smart Tag panel lets you create, open, or edit a Crystal report from a Web or Windows form. ReportSource and DataSource controls The ReportSource control contains a report that encapsulates the data, whereas a DataSource control (such as SqlDataSource) contains the data itself. The ReportSource control is also part of the simplified tag-based application development model provided with ASP.NET version 2.0. Automatic data binding With automatic data binding, you no longer need to call the DataBind() method in the codebehind class when binding to a file directory path through the Properties window.

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Report Interface Components


Reports driver Presentation Layer
Allows users to select from a list of available crystal reports based on multiple categories.
reportMenu.aspx

Middle Tier - A single .NET page that can launch any known report on demand.
reportDriver.aspx

Reports Layer - Repository of available reports


Financial Statement.rpt Sales by Category.rpt Employee Sales.rpt

DATA ACCESS LAYER (DAL) - Database tables used for application queries and report selection
PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Reports Database Table

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Report Selection

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Launch Report in CrystalViewer

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Source Code (reportMenu.aspx)


<div> <br />Report Category:<br /> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="reportCategory" DataValueField="reportCategory"> </asp:DropDownList> <br /> <br /> <asp:DataList ID="DataList1" runat="server" CellPadding="4" DataKeyField="ReportID" DataSourceID="SqlDataSource1" ForeColor="#333333"> <ItemTemplate> <a href="reportDriver.aspx?reportid=<%# Eval("ReportID") %>" target="_blank"><%# Eval("ReportTitle") %></a> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CRInterfaceConnectionString %>" SelectCommand="SELECT * FROM [Reports] WHERE ([ReportCategory] = @ReportCategory)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" DefaultValue="Feature Examples" Name="ReportCategory" PropertyName="SelectedValue" Type="String" /> </SelectParameters></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CRInterfaceConnectionString %>" SelectCommand="select distinct(reportCategory) from reports"></asp:SqlDataSource> </div>

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Source Code (reportDriver.aspx)


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="reportDriver.aspx.vb" Inherits="ReportDriver" %> <%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Crystal Reports Interface Example</title> </head> <body> <form id="form1" runat="server">

<div> <CR:CrystalReportViewer ID="CrystalReportViewer1" Runat="server" AutoDataBind="True" Height="947px" ReportSourceID="CrystalReportSource1" Width="845px" />


<CR:CrystalReportSource ID="CrystalReportSource1" runat="server" Report-FileName="CrystalReport1.rpt"></CR:CrystalReportSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CRInterfaceConnectionString %>" SelectCommand="SELECT * FROM [Reports] WHERE ([ReportID] = @ReportID)"> <SelectParameters> <asp:QueryStringParameter Name="ReportID" QueryStringField="reportid" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </div> </form> </body> </html>

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

VB Class (reportDriver.aspx.vb)
Partial Class ReportDriver Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.CrystalReportSource1.Report.FileName = getReportFileName() End Sub Private Function getReportFileName() Dim dv As System.Data.DataView = SqlDataSource1.Select(DataSourceSelectArguments.Empty) Return "reports/" & dv.Table.Rows(0)("ReportCategory") & "/" & dv.Table.Rows(0)("ReportFile") End Function End Class

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

Resources
My Contact Info: Charlie Parker PARKER Design Group, Inc. 1101 Pennsylvania Avenue, NW Suite 600 Washington, DC 20004 (202) 756-4980 charlie@homeshowcase.net

PARKER Design Group, Inc. - Crystal Reports and ASP.NET 2.0 Building a Web Reports Interface

You might also like