ASP.NET – SSRS SubReport DataSet Handling

ASP.NET – SSRS SubReport DataSet Handling

 
   using Microsoft.Reporting.WebForms;
 
   /* Pass it to ASP.NET MVC Controller – FileContentResult with PDF MIME for Exporting PDF */
   private byte[] Export_PDF()
   {
      ReportViewer viewer = new ReportViewer();
 
      viewer.ProcessingMode = ProcessingMode.Local;
      viewer.LocalReport.ReportPath = @"<Report File Path>";
 
      viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
      viewer.LocalReport.Refresh();
 
       … …
 
       /* Assign Master Report – DataSet & Parameter from here … */
 
       … …
 
      return viewer.LocalReport.Render("PDF");
   }
 
   private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
   {
      /* Assign From SubReport DataSet from here … */
      /* e.ReportPath – SubReport File Name */
      /* e.Parameters – SubReport Defined Parameter. The Parameter Value is passed from the Master Report */
      /* this.SoccerDataServices – Class Object of Business Logic Layer */
      /* would be executed in ( No. of Records from Master Report x No. of SubReport under Master Reports ) Times. */
      /* Try to make Each Query Performance Fast from here … */
      if (e.ReportPath == "RPTPlayer")
      {
         e.DataSources.Add(new ReportDataSource(
            "DataSet_PLAYER",
            this.SoccerDataServices.GetPlayer_LINQ(Int32.Parse(e.Parameters[0].Values[0].ToString()))
         ));
      }
      else if (e.ReportPath == "RPTTeam")
      {
         e.DataSources.Add(new ReportDataSource(
            "DataSet_TEAM",
            this.SoccerDataServices.GetTeam_LINQ(Int32.Parse(e.Parameters[0].Values[0].ToString()))
         ));
     &nbsp}
      else if (e.ReportPath == "RPTLeague")
      {
         e.DataSources.Add(new ReportDataSource(
            "DataSet_LEAGUE",
            this.SoccerDataServices.GetLeague_LINQ(Int32.Parse(e.Parameters[0].Values[0].ToString()))
         ));
      }
      else if (e.ReportPath == "RPTNation")
      {
         e.DataSources.Add(new ReportDataSource(
            "DataSet_NATION",
            this.SoccerDataServices.GetNation_LINQ(Int32.Parse(e.Parameters[0].Values[0].ToString()))
         ));
      }
      else if (e.ReportPath == "RPTStadium")
      {
         e.DataSources.Add(new ReportDataSource(
            "DataSet_STADIUM",
            this.SoccerDataServices.GetSTADIUM_LINQ(Int32.Parse(e.Parameters[0].Values[0].ToString()))
         ));
      }
   }
 

Remarks : "LocalReport_SubreportProcessing" Function can be enhanced to have the Generic Design Pattern.
It is only draft version of the SubReport DataSet Handling Feature.