In the downloadable project, the default.aspx file has a CrystalViewer object on it. To accomplish this, I just dragged and dropped the Crystal Report Viewer onto the default.aspx page (in design mode).
In code, binding the viewer to a report with a DataSet populated in the code-behind is similar to the methods used in VS 2003. But, utilizing the auto-created object makes this a little easier. First, create the object, and populate all the different tables. Then, create a Report object and bind it to the Business Object filled with all the data.
Listing 4: Bind the report to the viewer
CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
oRpt.Load(@"C:\Inetpub\wwwroot\FantasyReports\PlayerWithYards.rpt");
FFAssistantDataSet oDataSet = new FFAssistantDataSet();
PlayersTableAdapter oPlayers = new PlayersTableAdapter();
String strConn =
ConfigurationManager.ConnectionStrings["FFAssistantConnectionString"].ToString();
oPlayers.MainConnection = strConn;
oPlayers.Fill(oDataSet.Players);
TeamsTableAdapter oTeams = new TeamsTableAdapter();
oTeams.MainConnection = strConn;
oTeams.Fill(oDataSet.Teams);
StatsTableAdapter oStats = new StatsTableAdapter();
oStats.MainConnection = strConn;
oStats.Fill(oDataSet.Stats);
PositionsTableAdapter oPositions = new PositionsTableAdapter();
oPositions.MainConnection = strConn;
oPositions.Fill(oDataSet.Positions);
oRpt.SetDataSource(oDataSet);
CrystalReportViewer1.ReportSource = oRpt;
As you see in Listing 4, I set the connection string to the connection stored in the web.config file. This should look familiar if you are already binding data to your report using Visual Studio 2003. Just create a new ReportDocument object, and then load the report into that object. After filling the DataSet object with data, we bind it to the ReportDocument. Finally, the ReportDocument object is set as the ReportSource for the viewer. Build and run the web application and you'll see the report!