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:
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.
SQL Query |
Copy Code |
---|---|
SELECT CompanyName, ContactName, Phone, CustomerID FROM Customers ORDER BY CustomerID |
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 |
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. |
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%> |
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 |
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 |
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 |
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% |
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 |
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 |
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 |
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
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste JUST ABOVE the Viewer HyperLink event. |
Copy Code |
---|---|
Private LastCustID As String |
Visual Basic.NET code. Paste JUST BELOW the Viewer HyperLink event. |
Copy Code |
---|---|
Private Sub ClearViewer() Dim doc As DataDynamics.ActiveReports.Document.Document = viewer1.Document viewer1.Document = Nothing viewer1.Refresh() doc.Dispose() doc = Nothing End Sub |
Visual Basic.NET code. Paste INSIDE the Viewer HyperLink event. |
Copy Code |
---|---|
'Process hyperlink text. Dim report, parameter As String If e.HyperLink.IndexOf("\") > 0 And e.HyperLink.Length > 2 Then report = e.HyperLink.Substring(0, e.HyperLink.IndexOf("\")).ToUpper() parameter = e.HyperLink.Substring(e.HyperLink.IndexOf("\") + 1) Else MessageBox.Show("Cannot process hyperlink.") Return End If Dim rpt As DataDynamics.ActiveReports.ActiveReport = Nothing 'Determine which report to run. If report.CompareTo("CUSTOMERS") = 0 Then rpt = New rptCustomers() ElseIf report.CompareTo("ORDERS") = 0 Then rpt = New rptOrders() rpt.Parameters("CustomerID").Value = parameter LastCustID = parameter ElseIf report.CompareTo("PRODUCTS") = 0 Then rpt = New rptProductDetails(LastCustID) rpt.Parameters("ProductID").Value = parameter Else MessageBox.Show("Invalid report ID") End If 'Check whether a report object exists. If so, run and display it. If rpt IsNot Nothing Then ClearViewer() rpt.ShowParameterUI = False rpt.Run() Viewer1.Document = rpt.Document rpt.Dispose() rpt = Nothing End If |
To write the code in C#
The following example shows what the code for the method looks like.
C# code. Paste JUST ABOVE the viewer HyperLink event. |
Copy Code |
---|---|
private string LastCustID; |
C# code. Paste JUST BELOW the viewer HyperLink event. |
Copy Code |
---|---|
private void ClearViewer() { DataDynamics.ActiveReports.Document.Document doc = viewer1.Document; viewer1.Document = null; viewer1.Refresh(); doc.Dispose(); doc = null; } |
C# code. Paste INSIDE the viewer HyperLink event. |
Copy Code |
---|---|
//Process hyperlink text. string report, parameter; if (e.HyperLink.IndexOf('\\') > 0 && e.HyperLink.Length > 2) { report = e.HyperLink.Substring(0, e.HyperLink.IndexOf('\\')).ToUpper(); parameter = e.HyperLink.Substring(e.HyperLink.IndexOf('\\') + 1); } else { MessageBox.Show("Cannot process hyperlink."); return; } DataDynamics.ActiveReports.ActiveReport rpt = null; //Determine which report to run. if (report.CompareTo("CUSTOMERS") == 0) { rpt = new rptCustomers(); } else if (report.CompareTo("ORDERS") == 0) { rpt = new rptOrders(); rpt.Parameters["CustomerID"].Value = parameter; LastCustID = parameter; } else if (report.CompareTo("PRODUCTS") == 0) { rpt = new rptProductDetails(LastCustID); rpt.Parameters["ProductID"].Value = parameter; } else { MessageBox.Show("Invalid report ID"); } //Check whether a report object exists. If so, run and display it. if (rpt != null) { ClearViewer(); rpt.ShowParameterUI = false; rpt.Run(); viewer1.Document = rpt.Document; rpt.Dispose(); rpt = null; } |
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 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 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; } |
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; |