Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

3.09 ASP.NET Development

ASP.NET Development

The CrystalReportViewer control is the interface for previewing reports in an ASP.NET application. Adding a viewer control to a web page is as simple as dragging the control from the Toolbox onto the web page. After it is added to an ASP.NET page, it is represented by a simple rectangle.



Figure 3-2. The viewer control as positioned on an ASP.NET page.

If you worked through the Windows example where you added the viewer control to a form, you will immediately notice that the ASP.NET viewer looks different than the Windows viewer. When you add the viewer to an ASP.NET page, it only displays a simple rectangle. It doesn’t show you a template of what the viewer looks like.

Although the viewer control is very small when you add it to the web page, when you run the application it automatically grows to fill the remainder of the web page. It expands horizontally across the page as well as vertically down the page. This ensures that the report is readable when the page is displayed.

The viewer has a BestFitPage property (default value of True) that controls whether it fills the page or not. If you set this property to False, the viewer control will not resize itself and the report will be displayed within the bounds of the viewer. Setting it to False is useful when you want to limit the amount of space on the web page that is allocated to viewing reports. Obviously, if you decide to set BestFitPage to False, you should resize the viewer to make it large enough to comfortably display your report.

When BestFitPage property is True, the control does not expand upward. It only expands downward and across. Any information above the viewer control remains intact and properly formatted.

If the Page Layout is set to FlowLayout, all information below the viewer will be pushed down the page so that it appears after the viewer control. If the Page Layout is set to GridLayout, the information after the viewer control will not be pushed down. The ASP.NET controls will overlap the viewer control. This could either make for a very messy report or you could use it to add some interesting formatting effects.

As you can see in Figure 3-3, when the viewer is displayed in an ASP.NET page, it looks very similar to the report preview that you’ve seen with Windows applications.



Figure 3-3. The report preview in an Internet Explorer browser.

The ASP.NET viewer control has some interesting differences between it and the Windows viewer.

There are no tabs shown along the top of the ASP.NET viewer. When you drill down on reports in a web viewer, it opens a new page rather than showing all the tabs on a single page. There is also no Print button. A very disappointing aspect of the viewer is that it can’t send a report to the printer. You have to use the browser’s built-in print functionality to print the web page. This has the adverse effect of printing non-professional reports because it prints everything in the browser window. This includes the toolbar, the group tree and the web page information. Printing professional reports requires advanced programming techniques which are discussed in Chapter 19.

The last thing you might notice is the “Powered by Crystal” icon at the top of the toolbar. Although this is totally harmless, many people don’t like appearing it on their reports. You can get rid of this logo, or even replace it with your own, by deleting or overwriting the GIF file on your computer. You can find it within the Visual Studio .NET installation folder under “..\crystal reports\viewers\images\toolbar\logo.gif”

The properties of the Web viewer control are similar to that of the Windows viewer control. It has properties for changing the look of the viewer by hiding the toolbar, hiding the toolbar buttons and hiding the Group Tree window.

Although the Windows and Web viewer controls have properties that perform the same functionality, they often have different names. There are also certain properties that are unique to each control. Table 3-5 compares the common properties of each control so you can see the similarities and differences.