blockShow All / Hide All Link
Hyperlinks can be used in ActiveReports to pass values to parameters in other reports. This walkthrough illustrates how to set up hyperlinks in a report to simulate drill-down reporting.
This walkthrough is split up into the following activities:
- Connecting three reports to data sources
- Adding controls to each report to display data
- Creating a Windows Form Viewer
- Adding code to pass hyperlink values to parameters and open the drill-down report
- Adding code to set hyperlink properties to go back to the previous report
 |
Tip: For basic steps like adding a report to a Visual Studio project and viewing a report, please see the Basic Data Bound Reports walkthrough. |
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).
When you have finished this walkthrough, you will have reports that look similar to the following.
To connect three reports to data sources
- Add three reports to a Visual Studio project, naming them rptCustomers, rptOrders, and rptProductDetails.
- On rptCustomers, click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
- On the OLE DB tab, next to Connection String, click the Build button.
- In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
- Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to close the window and fill in the Connection String field.
- In the Query field, enter the following SQL query
| SQL Query |
Copy Code |
| SELECT CompanyName, ContactName, Phone, CustomerID FROM Customers ORDER BY CustomerID |
- Click OK to save the data source and return to the report design surface.
- On rptOrders, click the gray report DataSource icon on the Detail section band and connect it to Nwind.mdb.
- In the Query field, enter the following SQL query
| SQL Query |
Copy Code |
SELECT Orders.OrderID, Orders.CustomerID, Orders.OrderDate, Orders.ShippedDate, [Order Details].ProductID,
Products.ProductName, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount
FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID)
ON Products.ProductID = [Order Details].ProductID
WHERE Orders.CustomerID = '<%CustomerID||ALFKI%>'
ORDER BY Orders.OrderID, Products.ProductName
|
- Click OK to save the data source and return to the report design surface.
 |
Note: The SQL queries for rptOrders and rptProductDetails use parameters syntax: '<%CustomerID||ALFKI%>' and <%ProductID||1%>. Using a default value allows the Report Explorer to populate so you can drag fields onto the report. For more information on parameters, see the Parameters topic. |
- On rptProductDetails, click the gray report DataSource icon on the Detail section band and connect it to Nwind.mdb.
- In the Query field, enter the following SQL query
| SQL Query |
Copy Code |
SELECT Products.ProductID, Products.ProductName, Suppliers.CompanyName, Categories.CategoryName, Products.QuantityPerUnit,
Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.ReorderLevel, Products.Discontinued
FROM Categories
INNER JOIN (Suppliers INNER JOIN Products ON Suppliers.SupplierID = Products.SupplierID)
ON Categories.CategoryID = Products.CategoryID
WHERE Products.ProductID = <%ProductID||1%>
|
- Click OK to save the data source and return to the report design surface.
To format the reports and add controls to display data
Top-level Report: rptCustomers
- In the design view of rptCustomers, click to select the page header section, and in the Properties Window, change the following properties:
- BackColor: Gainsboro
- Height: 0.5
- Select the detail section, and set its properties as follows:
- BackColor: GhostWhite
- CanShrink: True
- Add the following controls to the indicated sections rptCustomers, setting their properties as indicated:
rptCustomers controls
| Control |
Section |
Location |
Size |
DataField |
Text |
Miscellaneous |
| Label |
PageHeader |
0, 0 in |
6.5, 0.198 in |
|
Customers |
Alignment = Center BackColor = SlateBlue ForeColor = White Font Size = 12 Font Style = Bold |
| Label |
PageHeader |
0, 0.26 in |
1.1, 0.198 in |
|
Company Name |
ForeColor = SlateBlue Font Style = Bold |
| Label |
PageHeader |
2.6, 0.26 in |
1, 0.198 in |
|
Contact Name |
ForeColor = SlateBlue Font Style = Bold |
| Label |
PageHeader |
4.3, 0.26 in |
1, 0.198 in |
|
Phone |
ForeColor = SlateBlue Font Style = Bold |
| Label |
PageHeader |
5.5, 0.26 in |
1, 0.198 in |
|
View Orders |
ForeColor = SlateBlue Font Style = Bold |
| TextBox |
Detail |
0, 0 in |
2.55, 0.2 in |
CompanyName |
|
|
| TextBox |
Detail |
2.6, 0 in |
1.6, 0.2 in |
ContactName |
|
|
| TextBox |
Detail |
4.3, 0 in |
1, 0.2 in |
Phone |
|
|
| TextBox |
Detail |
5.5, 0 in |
1, 0.2 in |
CustomerID |
|
(Name) = txtCustomerID1 |
Mid-level Report: rptOrders
- In the design view of rptOrders, click to select the page header section, and set its Height property to 0.5.
- Add the following controls to the page header section, setting their properties as indicated:
Page header controls for rptOrders
| Control |
Location |
Size |
DataField |
Text |
Miscellaneous |
| TextBox |
0, 0 in |
6.5, 0.198 in |
="Orders for Customer: " + CustomerID |
|
Alignment = Center Font Size = 12pt Font Style = Bold |
| Label |
0, 0.25 in |
6.5, 0.198 in |
|
Return to Customers |
Alignment = Center HyperLink = Customers\\Main |
- Right-click the report and select Insert, then GroupHeader/Footer.
- Set the group header properties as follows:
- BackColor: LightCyan
- DataField: OrderID
- Height: 0.5
- Add the following controls to the group header section, setting their properties as indicated:
Group header controls for rptOrders
| Control |
Location |
Size |
DataField |
Text |
Miscellaneous |
| Label |
0, 0 in |
1, 0.198 in |
|
Order Number |
BackColor = PaleTurquoise Font Style = Bold |
| TextBox |
1, 0 in |
0.5, 0.2 in |
OrderID |
|
BackColor = PaleTurquoise |
| Label |
2.26, 0 in |
1, 0.198 in |
|
Order Date |
Alignment = Right Font Style = Bold |
| TextBox |
3.34, 0 in |
1, 0.2 in |
OrderDate |
|
Alignment = Right OutputFormat = MM/dd/yy |
| Label |
4.44, 0 in |
1, 0.198 in |
|
Date Shipped |
Alignment = Right Font Style = Bold |
| TextBox |
5.5, 0 in |
1, 0.2 in |
ShippedDate |
|
Alignment = Right OutputFormat = MM/dd/yy |
| Line |
|
|
|
|
X1 = 0 X2 = 6.5 Y1 = 0.2 Y2 = 0.2 |
| Label |
0, 0.29 in |
1, 0.198 in |
|
Product ID |
Font Style = Bold |
| Label |
1, 0.29 in |
1, 0.198 in |
|
Product Name |
Alignment = Right Font Style = Bold |
| Label |
3.34, 0.29 in |
1, 0.198 in |
|
Unit Price |
Alignment = Right Font Style = Bold |
| Label |
4.44, 0.29 in |
1, 0.198 in |
|
Quantity |
Alignment = Right Font Style = Bold |
| Label |
5.5, 0.29 in |
1, 0.198 in |
|
Discount |
Alignment = Right Font Style = Bold |
- Click in the grey area below the report to select it, and set the ShowParameterUI property to False to avoid requesting parameters from the user.
- Select the detail section, and set its CanShrink property to True.
- From the Report Explorer, drag the following fields onto the detail section of rptOrders, setting their properties as indicated:
Detail section controls for rptOrders
| Field |
Location |
Size |
Miscellaneous |
| ProductID |
0, 0 in |
0.7, 0.2 in |
Alignment = Right (Name) = txtProductID1 |
| ProductName |
1, 0 in |
2.2, 0.2 in |
|
| UnitPrice |
3.34, 0 in |
1, 0.2 in |
Alignment = Right OutputFormat = $#,##0.00 |
| Quantity |
4.44, 0 in |
1, 0.2 in |
Alignment = Right |
| Discount |
5.5, 0 in |
1, 0.2 in |
Alignment = Right OutputFormat = 0% |
Lowest-Level Report: rptProductDetails
- Add a textbox to the page header section of rptProductDetails, setting its properties as indicated:
rptProductDetails controls
| Control |
Location |
Size |
DataField |
Miscellaneous |
| TextBox |
0, 0 in |
6.5, 0.2 in |
="Details for Product Number: " + ProductID |
Alignment = Center Font Style = Bold Font Size = 12pt |
- Add the following labels to the detail section, setting their properties as indicated:
rptProductDetails labels
| Location |
Size |
Text |
Miscellaneous |
| 0, 0 in |
1, 0.198 in |
Product Name |
Font Style = Bold |
| 0, 0.28 in |
1, 0.198 in |
Supplier |
Font Style = Bold |
| 0, 0.54 in |
1, 0.198 in |
Qty per Unit |
Font Style = Bold |
| 0, 0.83 in |
1, 0.198 in |
Units in Stock |
Font Style = Bold |
| 0, 1.12 in |
1, 0.198 in |
Reorder Level |
Font Style = Bold |
| 4.4, 0 in |
1, 0.198 in |
Category |
Font Style = Bold |
| 4.4, 0.28 in |
1, 0.198 in |
Discontinued |
Font Style = Bold |
| 4.4, 0.54 in |
1, 0.198 in |
Unit Price |
Font Style = Bold |
| 4.4, 0.83 in |
1, 0.198 in |
Units Pending |
Font Style = Bold |
- From the Report Explorer, drag the following fields onto the detail section, setting their properties as indicated:
rptProductDetails fields
| Field |
Location |
Size |
Miscellaneous |
| ProductName |
1.14, 0 in |
2.05, 0.2 in |
|
| CompanyName |
1.14, 0.28 in |
2.05, 0.2 in |
|
| QuantityPerUnit |
1.14, 0.54 in |
2.28, 0.2 in |
|
| UnitsInStock |
1.14, 0.83 in |
1, 0.2 in |
|
| ReorderLevel |
1.14, 1.12 in |
1, 0.2 in |
|
| CategoryName |
5.5, 0 in |
1, 0.2 in |
|
| Discontinued |
5.5, 0.28 in |
1, 0.2 in |
|
| UnitPrice |
5.5, 0.54 in |
1, 0.2 in |
OutputFormat = $#,##0.00 |
| UnitsOnOrder |
5.5, 0.83 in |
1, 0.2 in |
|
| TextBox |
Location |
Size |
Miscellaneous |
| ="Return to Orders for " + OrderID |
4.4, 1.125 in |
2.1, 0.2 in |
(Name) = txtReturnToOrders |
To add code to the viewer form for special hyperlink functions
This walkthrough assumes that you already know how to display a report in the viewer. For more information about these basic functions, see the Viewing Reports topic.
To write the code in Visual Basic
To write the code in C#
To add code to set the drill-down hyperlink in rptCustomers
- Double-click in the detail section to create a detail_Format event.
- Add code to the event to set the hyperlink of the Customer ID textbox to call the viewer code that passes the parameter to rptOrders.
To write the code in Visual Basic.NET
| Visual Basic.NET code. Paste INSIDE the Format event. |
Copy Code |
| txtCustomerID1.HyperLink = "Orders\" + txtCustomerID1.Text |
To write the code in C#
| C# code. Paste INSIDE the Format event. |
Copy Code |
| txtCustomerID1.HyperLink = "Orders\\" + txtCustomerID1.Text; |
To add code to set the drill-down hyperlink in rptOrders
- Double-click in the detail section to create a detail_Format event.
- Add code to the event to set the hyperlink of the Product ID textbox to call the viewer code that passes the parameter to rptProductDetails.
To write the code in Visual Basic.NET
| Visual Basic.NET code. Paste INSIDE the Format event. |
Copy Code |
| txtProductID1.HyperLink = "Products\" + txtProductID1.Text |
To write the code in C#
| C# code. Paste INSIDE the Format event. |
Copy Code |
| txtProductID1.HyperLink = "Products\\" + txtProductID1.Text; |
To add code to create a parameter to hold the previous report for rptProductDetails
- Right-click the report and select View Code.
- Add code to create a parameter for the previous report.
To write the code in Visual Basic.NET
| Visual Basic.NET code. Paste JUST BELOW the Public Class rptProductDetails line. |
Copy Code |
'The prevRptParam member is used to track the parameter for
'returning to the orders report for the correct customer
Private prevRptParam As String
Public Sub New(ByVal previousRptParameter As String)
InitializeComponent()
prevRptParam = previousRptParameter
End Sub
|
To write the code in C#
| C# code. Paste JUST BELOW the public partial class rptProductDetails() line. |
Copy Code |
//The prevRptParam member is used to track the parameter for
//returning to the orders report for the correct customer
private string prevRptParam;
public rptProductDetails(string previousRptParameter)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
prevRptParam = previousRptParameter;
}
|
| C# code. Paste INSIDE the parentheses in the public rptProductDetails() line. |
Copy Code |
| string previousRptParameter |
To add code to set the hyperlink to return to rptOrders in rptProductDetails
- Double-click in the detail section to create a detail_Format event.
- Add code to the event to set the hyperlink of the Return to Orders textbox to call the code that passes the parameter to rptProductDetails.
To write the code in Visual Basic.NET
| Visual Basic.NET code. Paste INSIDE the Format event. |
Copy Code |
Me.txtReturnToOrders.Text = Me.txtReturnToOrders.Text + prevRptParam
Me.txtReturnToOrders.HyperLink = "Orders\" + prevRptParam
|
To write the code in C#
| C# code. Paste INSIDE the Format event. |
Copy Code |
this.txtReturnToOrders.Text = this.txtReturnToOrders.Text + prevRptParam;
this.txtReturnToOrders.HyperLink = "Orders\\" + prevRptParam;
|
See Also