ASP.NET 2.0 Reporting Revisited: Part II
Creating Drill-through Reports Using the ReportViewer
October 30, 2009
asp:Feature
LANGUAGES:C# | VB.NET
ASP.NETVERSIONS: 2.0
ASP.NET 2.0 Reporting Revisited: Part II
Creating Drill-through Reports Using the ReportViewer
By Dennis E. Rehm
In Part I we created a summary report with totals. Our goal isto be able to click on a total and go directly to a detail report itemizingthose items that make up the total. We created the first detail report, but didn tlinked them together. If you want to work along, you ll need to have completedthe work in the first article. We re simply going to pick up from the end ofthat article.
Linking the Detail Report to the Summary Report
We created linkage on the detail report side. Now we needto create the linkage on the summary report.
Open the summary report, OrderSummary.rdlc. We re using a matrixcontrol to display the data in our summary report. We ll need to enhance thematrix control in order to call the detail report we just created. We ll createa simple drill-through first, then enhance it when we create the second detailreport.
Right-click the Data cell, the one that contains=Sum(Fields!TotalOrderAmt.Value). Select Properties from the pop-up menu. TheTextbox Properties window will open. Click on the Navigation tab. Your windowshould look like Figure 1.
Figure 1: Creating the jump.
Under Hyperlink action click the Jump to reportradiobutton. Select OrderDetailInd in the dropdown list. Click the Parametersbutton to open the Parameters window (see Figure 2). Here we define our firstparameter. Under Parameter Name enter ProductID. Under Parameter Value, select=Fields!ProductID.Value from the dropdown list. The second parameter is namedCountryRegionCode and its value is =Fields!CountryRegionCode.Value. When you vedefined both parameters, click the OK button. This returns you to the TextboxProperties window. Again, click the OK button.
Figure 2: Defining the jumpparameters.
The report now has the linkage in place. The Order Summaryreport looks the same, but it now has hyperlink behavior defined. We need towrite a little code, then we ll be ready to test it. Save the report and closethe Report Designer.
Enhancing the Web Page for Drill-through to the IndividualOrder Detail Report
Open the Web page that contains the ReportViewer. Now thatwe ve added the drill-through report, we need an ObjectDataSource for it. Drag tothe Web page an ObjectDataSource from the Data section of the Toolkit. Use theSmartTag and select Configure Data Source. In the Configure Data Source window,select the OrderDetailIndRptTableAdapter in the dropdown list under Choose yourbusiness object. Click the Next button. Nothing needs to be changed for DefineData Methods. Click the Next button. You ll see our ProductID andCountryRegionCode parameters in Define Parameters. Do not link the parametersto anything. Click the Finish button.
We want to give this ObjectDataSource a more descriptiveID. Select it and in the Properties panel, change the ID to objDetailInd. The Webpage now has two ObjectDataSources, one for the original summary report and onefor the individual order detail report (see Figure 3).
Figure 3: Adding anObjectDataSource.
The only thing left to do is hook things together in code.Go to the code for the Web page. Add the following statement at the top of thecode page: