Viewing Reports in Web Forms

To view a report in a Web Form, you go through the same process of adding a new report to your ASP.NET applications and designing the report using the Report Expert. After you've designed the report, you must add the CrystalReportViewer control from the Web Forms Toolbox tab. At this point, things change slightly.

Earlier, you saw how to programmatically load a report at runtime. The method of loading a report into the Web Form viewer control is the same. If you want to set the ReportSource property at design time, you must select the DataBindings property from the Properties window of the report viewer. Figure 18.21 demonstrates the DataBindings dialog box for a report viewer. Notice the ReportSource property—I've entered the path to a valid report file that I created.

Figure 18.21. Setting the DataBindings of a Web report at design time.


When the ReportSource property is set, a report appears in the Web Form with phony data, as Figure 18.22 demonstrates.

Figure 18.22. A report loaded into the Web Form viewer.


At this point, the viewer is aware of the report that it must display. To actually bind that data from the data source to the report, you must call the DataBind method of the Page class to make the report viewable at runtime. The following C# snippet calls the DataBind method:

Page.DataBind();

This code must go in the Page_Load event in the code-behind of the page with the viewer. After the DataBind method executes, the report binds to the data source, and loads in the browser viewer. You'll notice in the following code that the ReportSource property is set in the viewer object in the HTML of the Web Form:

<CR:CrystalReportViewer id=CrystalReportViewer1 "
ReportSource='<%# "C:InetpubwwwrootCrystalWebTestWebReport1.rpt" %>'>
</CR:CrystalReportViewer>

When you load a report into the Web Form viewer control, there's no printing capability. That means no Print button shows up on the toolbar for the viewer. You must use the regular File, Print menu to print the reports displayed in the browser.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.108.175