How to: Create Report Viewers
To render a report in a dashboard, a Web server control for that report must reside on the Web server that hosts the report. This control renders the HTML for the report, provides logic to handle any report parameters, and retrieves the report view object from the server.
To create a Web server control for a custom report, you must implement a class that is derived from ParameterizableControl, which inherits from System.Web.UI.WebControl. The ParameterizableControl class provides access to any report parameters and to the methods in the Web server control that display the report.
Implementing ParameterizableControl
The following code example renders a "MyReportViewDocument" report type in a SharePoint Web page or ASP.NET Web page.
Prerequisites
Before you compile the code example, ensure you have met the following prerequisites:
Install PerformancePoint Monitoring Server.
Install the My Report View sample. To download the sample, see Creating a Custom Report View Plug-in for PerformancePoint Server 2007 ~ Code Sample.
Be prepared to sign your DLL with a strong name. In addition, ensure that all assemblies referenced by your DLL have strong names. For information about how to sign an assembly with a strong name and how to create a public/private key pair, see How to: Create a Public/Private KeyPair.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Xml.Serialization;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Server;
using Microsoft.PerformancePoint.Scorecards.Server.Extensions;
using MyReportViewPluginClient;
namespace MyReportViewPluginServer
{
public class MyReportViewWebControl : ParameterizableControl
{
// Render the HTML output for the report.
protected override void Render(HtmlTextWriter output)
{
// Get data. Some data is design-time data and
// some is browser-time data.
Dashboard dashBoard = PmServer.GlobalServer.GetDashboard(this.DashboardId);
DashboardItem dashboardItem = dashBoard.FindDashboardItem(this.DashboardItemId);
ReportView reportView = PmServer.GlobalServer.GetReportView(dashboardItem.UnderlyingElementId);
NameValueCollection parameterValues = new NameValueCollection();
try
{
foreach (ParameterMessage parameter in this.Parameters)
{
DataTable dataTable = parameter.Values;
foreach (DataRow row in dataTable.Rows)
{
string parameterName = row["MemberUniqueName"].ToString();
string parameterValue = row["DisplayValue"].ToString();
parameterValues.Add(parameterName, parameterValue);
}
}
}
catch
{
parameterValues = new NameValueCollection();
}
string documentXml = reportView.CustomData;
StringReader stringReader = new StringReader(documentXml);
XmlSerializer deserializer = new XmlSerializer(typeof(MyReportViewDocument));
MyReportViewDocument myReportViewDocument = (MyReportViewDocument)deserializer.Deserialize(stringReader);
stringReader.Close();
// Convert the data to a list of dataItems.
// Replace this with your custom code.
List<string> dataItems = new List<string>();
dataItems.Add("Data entered into the Dashboard Designer (MyReportViewEditorPanel):");
if (string.IsNullOrEmpty(myReportViewDocument.MyCustomData))
{
dataItems.Add(" No data was entered at design time.");
}
else
{
dataItems.Add(" " + myReportViewDocument.MyCustomData);
}
dataItems.Add(string.Empty);
dataItems.Add("Data received by this web control (MyReportViewWebControl) at browser time:");
if (parameterValues.Count < 1)
{
dataItems.Add(" No parameters were received");
}
else
{
foreach (string parameterName in parameterValues.Keys)
{
dataItems.Add(" " + parameterName + " = " + parameterValues[parameterName]);
}
}
// Render the dataItems as an HTML table.
// Replace this with your custom code.
output.WriteLine("<table style=\"font-family:verdana,tahoma,helvetica;font-size:9pt;\">");
foreach (string dataItem in dataItems)
{
string dataItemHtml = dataItem;
if (string.IsNullOrEmpty(dataItemHtml))
{
dataItemHtml = " ";
}
else
{
dataItemHtml = dataItemHtml.Replace(" ", " ");
}
output.WriteLine("<tr><td>" + dataItemHtml + "</td></tr>");
}
output.WriteLine("</table>");
}
}
}
See Also
Tasks
How to: Install Report Viewer Extensions
Concepts
How to: Create Report Designers