王朝网络
分享
 
 
 

crystal reports for Visual Studio .NET(webformsample)

王朝c#·作者佚名  2006-01-09
宽屏版  字体: |||超大  

Crystal Reports ®

For Visual Studio .NET®

Interactivity and Reports in Web Applications

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 2

© 2003 Crystal Decisions, Inc. Crystal Decisions, Crystal Reports, Crystal Enterprise,

Crystal Analysis, Crystal Services, Crystal Care, Crystal Assist, Crystal Applications, Info

and Holos are trademarks or registered trademarks of Crystal Decisions, Inc. in the U.S.

and/or other countries. All other trademarks or registered trademarks referenced are the

property of their respective owners.

Version 2.0

Crystal Decisions, Inc.

895 Emerson Street

Palo Alto, CA 94301

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 3

Interactivity and Reports in Web Applications

Introduction

You can use the Integrated Development Environment (IDE) in Visual Studio .NET to create

interactivity in your application that hosts Crystal reports.

In this walkthrough, you will create a Web application using Active Server Pages.NET

(ASP.NET) in Visual Studio .NET. The Web application contains two Web Form controls: an

image and a Web Forms Viewer. It supports interactivity between the user and the Web

Forms Viewer, and interactivity between the Web Forms Viewer and the image control.

For more information and updates, please visit our Web site at:

http://www.crystaldecisions.com/net.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 4

Outline of the Web Application

The Web application will contain these controls:

· a Web Forms Viewer control hosting a report containing a group tree and three charts

(which will be referred to as Chart A, Chart B and Chart C). Users can traverse the group

tree and drill down on Chart A to select a country.

· an image control that will display a flag corresponding to the country the user has

chosen from Chart A.

The Chain of Interactions

1. The user selects a country through the Web Forms Viewer control by drilling down in

Chart A of the report.

2. The Web Forms Viewer updates its display of the report based on the selected country.

3. The image control accepts the chosen country and displays the corresponding flag for

that country.

Supporting Files

The following report and image files have been provided with this walkthrough:

· Sales By Country.rpt

· USA.jpg

· England.jpg

· France.jpg

· Germany.jpg

· Italy.jpg

· Others.jpg

They are available for download from our Web site as supporting files at:

http://www.crystaldecisions.com/net.

Create the folder "WalkthroughFiles" under the directory c:\Inetpub\wwwroot. Copy or

download the report and image files to this folder.

The following sections explain how to construct the Web application described above, and

how to navigate in Sales By Country.rpt in a Web Forms Viewer.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 5

Creating the Web application

Below, you will create a Visual C# Web application that has a Web Forms Viewer hosting

Sales By Country.rpt, and an image control displaying the flag of the country the user has

chosen through the report. Sales By Country.rpt assumes that the sample database,

xtreme.mdb, has been installed on C:\Program Files\Microsoft Visual Studio .NET\Crystal

Reports\Samples\Database during setup for Visual Studio .NET.

To change the location of xtreme.mdb

If you have installed xtreme.mdb at a location other than the default (i.e., C:\Program

Files\Microsoft Visual Studio 7\Crystal Reports\Samples\Database), you should do a Set

Location for Sales By Country.rpt. To do a Set Location:

1. In Visual Studio .NET, select File | Open |File. This invokes the Open File dialog box.

2. In the Open File dialog box, browse to the location c:\Inetpub\wwwrootWalkthroughFiles, and specify the file Sales By Country.rpt. This opens Sales By

Country.rpt in the Crystal Report Designer.

NOTE If the Crystal Decisions Registration Wizard appears, you can choose to

register the Crystal Report Designer at this point or at a later time.

3. In the Crystal Report Designer, right-click in a report area. Choose Database | Set

Location. This invokes the Set Location dialog box.

4. In the Set Location dialog box, click the down-arrow under Current Data Source.

Select the data source assumed by Sales By Country.rpt, C:\Program Files\Microsoft

Visual Studio .NET\Crystal Reports\Samples\Database\xtreme.mdb. You will

point this assumed location to the actual location of the database.

5. You may use any one of these database technologies to connect the report to the actual

data source: OLE DB (ADO), ODBC (RDO), Database Files (i.e., using native drivers), or

ADO.NET (XML) (which is under More Data Sources). For the purpose of this

walkthrough, under Replace with, double-click OLE DB (ADO). This invokes the OLE

DB (ADO) dialog box.

NOTE If you are already connected to xtreme.mdb, proceed with step 9. Or, if you

are connected to another database through OLE DB (ADO), select Make New

Connection.

6. In the OLE DB (ADO) dialog box, highlight the OLD DB provider, Microsoft Jet 4.0

OLEDB Provider. Then click the Next button.

7. Provide the necessary information to access the actual data source: for Database

Name, click the square button adjacent to the entry box. Select xtreme.mdb according

to where you have installed it. Click Next.

8. Update any advanced information for your data source, if necessary. Then click Finish.

You will be returned to the Set Location dialog box.

9. Redirect the report to look for the database in the actual location: in the Set Location

dialog box, under Replace with, highlight the actual location of the database. Click

Replace. You will find this location updated under Current Data Source. Then click

Close.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 6

10. If you have modified fields in xtreme.mdb, right-click in a report area, point to

Database and select Verify Database. A message titled Verify Database suggests

you to proceed to fix up the report. Click OK to fix up unmapped fields in the database.

11. Choose File | Save Sales By Country.rpt to save the report with the updated database

location.

Creating a Web Form

You will create a Visual C# Web application project, WebFormExample, on the local host

http://localhost.

1. In Visual Studio .NET, select File | New | Project. This invokes the New Project dialog

box.

2. In the New Project dialog box, select Visual C# Projects in the left pane.

3. Select ASP.NET Web Application in the right pane.

You may choose to create your project on any Web server of your choice. For the purpose of

this example, you will create the project in the default project location, http://localhost,

which is the local IIS Web server.

4. Enter "WebFormExample" in the Location field after http://localhost/. The default

project location, http://localhost, is displayed in the Location field. Click OK.

This creates the Web application project, WebFormExample, at

http://localhost/WebFormExample.

Visual Studio creates a Web Forms page (with the default name "WebForm1.aspx") in

the project WebFormExample.

The window for the Web Forms page consists of two tabs: Design and HTML. The Design

tab allows programming using the Visual Studio IDE. The HTML tab contains the HTML

source that supports ASP.NET. Visual Studio automatically opens the Design tab of

WebForm1.aspx.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 7

TIP In Visual Studio .NET, you can anchor the Toolbox by clicking the "pin" icon at

the top-right corner of the Toolbox.

Also, items in a Toolbox tab can be displayed alphabetically by right-clicking the tab,

and selecting Sort Items Alphabetically from the shortcut menu.

When you are in the Design

tab, the Toolbox lists the Web

Form controls.

The Web Forms tab of the

Toolbox displays all Web Form

controls including the Web Forms

Viewer.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 8

Inserting the Web Form Controls

With the Toolbox set up properly, you can now insert Web Form controls into your Web

Form. Select the Design tab of WebForm1.aspx if it is not already the active tab. You will

insert two controls, an image and a Web Forms Viewer:

1. From the Web Forms tab of the Toolbox, drag the Image control and drop it into the

Web Form. The image object has a default name Image1.

2. Similarly, drag a Web Forms Viewer control and drop it into the Web Form. The Viewer

has a default name CrystalReportViewer1.

Web Forms

Viewer control

Image control

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 9

Binding Files to the Web Forms Controls

Next, you will specify the image and report files that the Web Form will display.

Initialize the image control with a United Nations flag since initially, no country has been

chosen. Later in the section "Linking Up the Web Form Controls for Interactivity", you will

further specify which flag the image control should display under what conditions.

To specify an image file for the image control:

1. In the Design tab of WebForm1.aspx, select the image control. The Properties window

automatically displays the properties applicable to the image control. You may click the

Alphabetize icon to arrange properties in their alphabetical order.

2. Scroll down to the property, ImageUrl, in the Properties window. Specify a URL or full

path name for the image file that you would like the image control to display. Specify

the URL http://localhost/WalkthroughFiles/Others.jpg. This initializes the image

control to display the flag for the United Nations.

3. You may adjust the length and the width of the image control to display the flag in the

appropriate scale.

To specify a report file for the Web Forms Viewer control

1. In the Design tab of WebForm1.aspx, select the Web Forms Viewer control. The

Properties window automatically displays the properties applicable to it.

2. Select DataBindings in the Properties window, and click the square button to the right

of the entry field. This opens the DataBindings dialog box.

3. In the DataBindings dialog box, select ReportSource under Bindable Properties,

and enter the full path name, "C:\\Inetpub\\wwwroot\\WalkthroughFiles\\Sales By

Country.rpt" (with the double quotes) under Custom binding expression. The Web

Forms Viewer control automatically displays this report at design time.

Specify image to display.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 10

4. Highlight WebForm1.aspx in the Solution Explorer and click the View Code icon. In

WebForm1.aspx.cs, after the call to base.OnInit(e) in OnInit, enter this line:

DataBind();

5. You may adjust the size of the Web Forms Viewer control as you see fit, by first setting

the property, BestFitPage, to False, and then adjusting handles of the Viewer in the

Design tab.

Select the ReportSource

property under Bindable

Properties.

Specify a full path name

for the report file.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 11

Below shows a layout of the Web Form in the Visual Studio editor, with the image and Web

Forms Viewer controls initialized.

Linking Up the Web Form Controls for Interactivity

As described in the section "Outline of Web Application" above, when the user drills down on

a country (or a group of countries for "Others") in Chart A in the report, the image control

should display the appropriate flag.

To set up the image control to display the appropriate image upon a drill-down event in the

Web Forms Viewer, you can implement the following:

1. In the Design tab of WebForm1.aspx, select the Web Forms Viewer control.

2. In the Properties window, click the Events icon. The Properties window automatically

displays all the events applicable to the Web Forms Viewer control. If you have not

already done so, you may click the Alphabetize icon to arrange events in their

alphabetical order.

3. Double-click the Drill event. This activates the editor for WebForm1.cs, and initializes a

function named CrystalReportViewer1_Drill.

4. Add the following lines of code to CrystalReportViewer1_Drill:

string sGroupName = "";

if (e.NewGroupLevel == 1)

{

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 12

sGroupName = e.NewGroupName;

string imageURL = string.Format

("http://localhost//WalkthroughFiles//{0}.jpg", sGroupName);

Image1.ImageUrl = imageURL;

}

Building and Running the Web application

To build and run the Web application:

1. From the Visual Studio .NET Menu Bar, select File | Save All to save all changes you

have made to the project WebFormExample. The first time you save the solution file,

you will be prompted with a message about saving WebFormExample.sln. Save it to the

default location c:\Inetpub\wwwroot\WebFormExample.

2. Select Build | Build to compile your application.

3. Select Start Without Debugging from the Debug menu.

4. The Web application automatically starts at

http://localhost/WebFormExample/WebForm1.aspx in your browser.

5. Try drilling down on a country in Chart A of Sales By Country.rpt. For instance, drill

down on USA. The image control displays the flag of the United States. The report also

displays Chart B showing the sum of last year's sales for the top 5 regions in the United

States.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 13

Navigating in the Crystal Report

Sales By Country.rpt is grouped by the four fields - country, region, city and customer

name. It contains a group tree and charts A, B and C. You can select a grouping via the

group tree. You can also select a country grouping through Chart A.

Drilling Down in the Crystal Report

Initially, to select a grouping via the group tree, expand the group tree by clicking on the '+'

symbol to the left of a country node. You can then click a region, city, or customer name.

The report will then display the sum of last year's sales for the selected grouping.

You can also select a country grouping by drilling down on Chart A. Chart A is a group chart

displaying the sum of last year's sales for each of the top 5 countries, and the total of last

year's sales for the rest of the countries. The user may drill down (by clicking) on Chart A to

select one of the top 5 countries (or "Others" for all other countries), and view in Chart B

the sum of last year's sales for each of the top 5 regions in that country (or group of

countries in the case of "Others").

You can expand and

traverse the group tree to

select a grouping.

Or, you can select a

country in Chart A by

drilling down on it.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 14

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 15

For instance, to view the sum of last year's sales for the top 5 regions in Italy, you can drill

down on "Italy" in Chart A. In this database, since there are only 3 regions in Italy (i.e.,

Lombardia, Piedmonte and Lazio) with sales, only the sum of last year's sales of each of

these 3 regions will be displayed in Chart B.

Click on a region or expand

the group tree to select a

city or customer.

Chart B displays the sum of last

year's sales in the top regions of

the country selected in Chart A.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 16

At this point, you may click a region in the group tree, or further expand the group tree to

select a city or customer to display the corresponding sales. For instance, you can click the

region, Lombardia, in the group tree. The report will display in Chart C the sum of last year's

sales of the two cities in Lombardia, Bergamo and Milan.

Clicking a region will display the

sales of each city in that region.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page 17

You may further expand the group tree and select a city or customer name to display the

corresponding sales for that city or customer. For example, if you click the city Milan, the

report will show the sales for each customer in Milan; in this database, since there is only

one customer, Milano Bike Store, in Milan, the report will only show the sales for that

customer.

Note that at any point, you can click the up-arrow icon in the Web Forms Viewer toolbar to

traverse one level up in the group tree.

Clicking on a city in the group

tree will show sales of each

customer in that city.

You can click the up-arrow icon

anytime to traverse one level up

in the group tree.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有