HOW DOES DRILLTHROUGH REPORTING HELP?

Adding DrillThrough functionality make reporting powerful and useful. It gives the user the ability to see data and information in more detail and allows the user to pass from one report to another while still analyzing the same set of data. This greatly enhances the user's understanding of the data. Any user working with ActiveReports 8 would also want it to support this feature, regardless of the platform being used. If we talk about the support for drilldown in a Section Based Report then it is simple to implement if we are working with Windows Forms Viewer control. Since drillthrough functionality is achieved with the help of hyperlinks, the HyperLink event makes it easy for the user to check if a hyperlink was clicked and perform the required operations. However if we are working with a web application and using FlashViewer to display the reports then there is no direct way of implementing this feature. Fortunately, the client API of the FlashViewer provides us one way of doing it.

WHAT WE NEED

Before we start focusing on the implementation, it is important to understand about the set of methods, events and classes working behind the scene. Let us take a quick look at them:

  1. RpxHandler: The RpxHandler loads the RPX file into ActiveReports, runs and exports it to a specified format, defaulting to HTML. We need this to pick up the child report, pass the parameter from the main report and display the relevant records in the FlashViewer.
  2. OnLinkClick(LinkEventArgs): This is the client side event which is raised when a hyperlink is clicked on the report being displayed in the FlashViewer.
  3. Parameters: We would need to pass the name of the clicked hyperlink on the main report as parameter to the child report. This is required to show the related set of records in the child report. As mentioned above, this action would be performed by the RpxHandler.

Having discussed the required ingredients, let us take a quick preview of our final cooked recipe. In this example, we are showing a list of countries which can be clicked to show the corresponding company name and city: InitialDisplay

IMPLEMENTATION

It is time now to concentrate on the implementation. Make sure that the "UseClientApi" property for the FlashViewer control is set to true else none of our client side code will work. In this example we are using the Code Based Report as the parent report and XML Based Report as the child report. First thing we need to do is to set the "Hyperlink" property for the textbox placed in the main report. This is required since we would need to get this value when we handle the click of the hyperlink. This is the easy part and a single line of code works well.

private void detail_Format(object sender, EventArgs e)  
{  
   if (txtCountry1.Text != "")  
   {  
      txtCountry1.HyperLink = txtCountry1.Text;  
   }  
}

Once this is done, the client side API of the FlashViewer comes into play. Here we will handle the OnLinkClick event and get the text of the clicked hyperlink. Next, we will pass this value as parameter to the child report and load it into the FlashViewer. The following script code does the trick.

var viewer;  
function init() {  
   GrapeCity.ActiveReports.Viewer.OnLoad("WebViewer1", function () {  
      viewer = GrapeCity.ActiveReports.Viewer.Attach("WebViewer1");  
      viewer.setEventsHandler({  
         OnLinkClick: function (e) {  
            var _paramValue = e.Link;  
            viewer.LoadDocument("SectionReport2.rpx?parameter1=" + _paramValue + "&OutputFormat=Rdf3");  
            return true;  
         }  
      });  
   });  
}

Since we would also want to return to the parent report, we would store the main report instance in a session and load it upon a button click. The following code shows how this can be done.

protected void Page_Load(object sender, EventArgs e)  
{  
   if (!IsPostBack)  
   {  
      SectionReport1 rpt = new SectionReport1();  
      WebViewer1.Report = rpt;  
      Session["Report"] = rpt;  
   }  
}  

protected void btnLoad_Click(object sender, EventArgs e)  
{  
   WebViewer1.Report = ((GrapeCity.ActiveReports.SectionReport)Session["Report"]);  
}

So we are good to go. A sample application for this implementation can be found here. Also see it in action below. I hope this helps. DrillDown