1.
Launch another instance of Visual Studio.
2.
Select File -> New Web Site from the menu.
3.
Choose ASP.NET Web Site from the list of templates.
4.
Choose "File" for the location.
5.
Enter "ReportingWebSite" for the name of the web site. The
path should be "..\Visual Studio 2008\WebSites\ReportingWebSite"
6.
Click the OK button.
7.
Open the Markup for the Default.aspx page if it isn't already open.
8.
Copy the following Register directive after the Page directive.
Listing 1
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
9.
Enter the following between the div tags.
Listing 2
Select a customer:<asp:DropDownList ID="ddlCustomer" runat="server">
</asp:DropDownList>
<asp:Button ID="btnPreview" runat="server" onclick="btnPreview_Click"
Text="Preview" />
<br />
<br />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />
10. Click
the Design button. Your design environment should look like the following
image.

11. Double
click on the Preview button to generate the click event handler.
12. Enter
the following code for the click event.
Listing 3
protected void btnPreview_Click(object sender, EventArgs e)
{
BindReport();
CrystalReportViewer1.Visible = true;
}
13. Create
the BindReport method.
Listing 4
private void BindReport()
{
CrystalReportViewer1.ReportSource =
"http://localhost:2632/ReportingService/InvoiceService.asmx";
CrystalReportViewer1.SelectionFormula = "{SalesOrderHeader.ContactID} = "
+ ddlCustomer.SelectedItem.Value;
}
14. ReplaceCrystalReportViewer1.ReportSource
= "http://localhost:2632/ReportingService/InvoiceService.asmx"; with
the path to the web service you created in step 3. If you have the browser
still running from step 3 you can copy and paste the URL from the browser.
15. Add
the code to the Form Load event to load the customer drop down list.
Listing 5
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Load the drop down list with customers.
SqlConnection cn = new SqlConnection(
ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString);
cn.Open();
SqlCommand cmd = new SqlCommand(
"SELECT DISTINCT LastName + ', ' + FirstName AS Name, Person.Contact.ContactID " +
"FROM Sales.SalesOrderHeader " +
"INNER JOIN Person.Contact " +
"ON Sales.SalesOrderHeader.ContactID = Person.Contact.ContactID " +
"ORDER BY LastName + ', ' + FirstName", cn);
SqlDataReader dr = cmd.ExecuteReader();
ddlCustomer.DataSource = dr;
ddlCustomer.DataTextField = "Name";
ddlCustomer.DataValueField = "ContactId";
ddlCustomer.DataBind();
CrystalReportViewer1.Visible = false;
}
else
{
if (CrystalReportViewer1.Visible == true)
{
//Rebind the report.
BindReport();
}
}
}
16. Add
the connection string for the AdventureWorks database to the web.config file.
Be sure to set the server, user name and password for your database.
Listing 6
<connectionStrings>
<add name="AdventureWorks" connectionString=
"Data Source=YOURSERVER\SQL2008;User ID=aspalliance;Password=aspalliance;
Initial Catalog=AdventureWorks;"/>
</connectionStrings>
17. Add
the following using statements to the top of you file.
Listing 7
//Custom using statements
using System.Data.SqlClient;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
18. Press
F5 to run the web site. You'll be prompted to enable debugging for the web
site. Click the OK button.
19. The
Default page should be displayed and the customer drop down list should be populated
with the list of customers.

20. Select
Abercrombie, Kim from the drop down list and click the Preview button.
21. You
should see the following report.

The BindReport method does all the work. The first line
tells the viewer where the report is located.
Listing 8
CrystalReportViewer1.ReportSource =
"http://localhost:2632/ReportingService/InvoiceService.asmx";
The second line sets the selection formula for the report so
only the selected customer is displayed in the report.
Listing 9
CrystalReportViewer1.SelectionFormula = "{SalesOrderHeader.ContactID} = "
+ ddlCustomer.SelectedItem.Value;