Users of ActiveReports would surely agree to the fact that ActiveReports has been a revolution in terms of customizable Reporting component. ActiveReports in conjunction with default .NET libraries has been developer's delight irrespective of the domain whether it is Windows development, ASP.NET, WPF or be it Silverlight. With simple tweaking, it can be used to meet the develover's requirement. One such scenario has been the loading of ActiveReports in SilverlightViewer where the requirement is to pass the parameters silently without requiring end users to input the values. Implementation of the above scenario has already been discussed in one of my blogs where the similar requirement has been implemented for SectionReports. You can go through the article from this link. This blog discuss the same implementation for the developers working with PageReports. Difference between the two implementation lies only how the Parameter is fed into the PageReports. Before we look ahead with the implementation, lets quickly have a look at how the report would work in Silverlight Viewer. PageReportParameter

Design the Silverlight Page

To begin with, create a Silverlight application with Web Project included. Add a ComboBox control and a SilverlightViewer object to the MainPage of the Silverlight project.


<Grid x:Name="LayoutRoot" Background="White">  
  <Grid.RowDefinitions>  
     <RowDefinition Height="35"/>  
     <RowDefinition/>  
  </Grid.RowDefinitions>  
  <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="30" Margin="10,0,0,0">  
      <TextBlock Text="Select a city from dropdown list" Padding="10"/>  
      <ComboBox Name="idCombo" Width="125" SelectionChanged="idCombo_SelectionChanged">  
        <ComboBoxItem Content="1"/>  
        <ComboBoxItem Content="2"/>  
        <ComboBoxItem Content="3"/>  
        <ComboBoxItem Content="4"/>  
      </ComboBox>  
  </StackPanel>  
  <ActiveReports:Viewer Name="SLViewer" Grid.Row="1"/>  
</Grid>  

Add SectionReport to the Web Project

In this phase, you add a parameteric PageReport and design all the required fields. For details to design a parametric PageReport, you can refer this documentation link.

Working with Parametric WebForm

Similar to the SectionReports implementation, the core concept is to pass the parameter as query string to a web form which will run the reports object using the parametric query string in its datasource command. Report is saved in RDL format and returned back as stream to be consumed by the Silverlight Page. Add a web form 'ReportParameters.aspx'to the web project of the Silverlight application and use the code mentioned below. Following code block is the heart of this blog implementation.


protected void Page_Load(object sender, EventArgs e)  
{  
   if (Request.QueryString["ParamData"] != "")  
   {  
      System.IO.FileInfo rptPath = new System.IO.FileInfo(Server.MapPath("~") + "\\\ParametricPageReport.rdlx");  
      string paramString = Request.QueryString["ParamData"];  
      GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);  
      pageReport.Report.ReportParameters[0].DefaultValue.Values.Add(paramString);  

      GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension rdfre = new GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension();  

      pageReport.Run();  
      GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider msp = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();  

      pageReport.Document.Render(rdfre, msp);  

      Response.BinaryWrite((msp.GetPrimaryStream().OpenStream() as MemoryStream).ToArray());  
      Response.End();  
   }  
}  

Generate Report Based on ComboBox Selection

This section shows how the query string is passed to the webform and retrieve the RDL stream for display in the Silverlight Viewer.


private void idCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)  
{  
   var currenthost = string.Format("http://{0}:{1}/",  
   Application.Current.Host.Source.DnsSafeHost, Application.Current.Host.Source.Port);  

   Uri codeuri = new Uri(currenthost + "ReportParam.aspx?ReportType=Page&ParamData=" + ((ContentControl)(idCombo.SelectedValue)).Content.ToString());  
   WebClient codereport = new WebClient();  
   codereport.OpenReadCompleted += new OpenReadCompletedEventHandler(client_ClientOpenReadCompleted);  
   codereport.OpenReadAsync(codeuri);  
}  

private void client_ClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)  
{  
   if (e.Result != null)  
   {  
      Stream rdlx = (Stream)e.Result;  
      LoadRDLXReportFromStream(rdlx);  
   }  
}  

private void LoadRDLXReportFromStream(Stream stream)  
{  
   //Loads the RDF stream and displays in the Silverlight Viewer  
   SLViewer.LoadDocument(new GrapeCity.Viewer.Common.StreamDocumentLoader(stream, GrapeCity.Viewer.Common.DocumentFormat.Rdf));  
}  

This brings to the end of series of blogs where we have seen how the parameters can be passed to ActiveReports in SilverlightApplication without any user input. You can refer to the complete code implementation in the sample below. Download Sample