Demonstration of SSRS reports in ASP.Net

Posted by Techie Cocktail | 4:05 PM | | 0 comments »

The SSRS reports can be integrated in asp.net page using the available 'MicrosoftReportViewer' Control in the toolbox under Reporting tab (Microsoft Visual Studio 2008). This implementation assumes that you have already created SSRS reports and have hosted them on a web server.

This implementation uses - Menu Control, XML Datasource to bind XML Data to the menu control & the Microsoft Report Viewer control. The menu control is bound to the XML data file via the XMLDatasource to create menu items. When the user clicks on the menu item, the underlying data of the menu item is assigned to the ReportViewer’s report path property and the corresponding report is called & displayed in the Report Viewer Control.

Below is the Source code of the above mentioned:

1. Sample XML file - sitemap.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Menu text="Parent Node" url="">
<subMenu text="Child Node" url="/SSRSReports/Report1"/>
</Menu>

2. Attach sitemap.xml to the XMLDatasource using the XMLDatasource’s DataFile Property:

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/sitemap.xml"></asp:XmlDataSource>

3. Attach the XML Datasource to the ASP.Net Menu control by assigining the XMLDataSource ID property value to the asp.net menu control DataSourceID property:

<asp:Menu ID="mnu_Main" runat="server" DataSourceID="XmlDataSource1" />

4. Bind the menu items in the menu with the xml file using the DataBindings collection:

<DataBindings>
<asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="url" />
<asp:MenuItemBinding DataMember="subMenu" TextField="text" ValueField="url" />
</DataBindings>

5. Put this code in the MenuItemClick event:

if (e.Item.Value != null)
{
ReportViewer1.Reset();
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://<ServerName>/ReportServer");
ReportViewer1.ServerReport.ReportPath = e.Item.Value;
ReportViewer1.ShowParameterPrompts = true;
ReportViewer1.ShowBackButton = true;
ReportViewer1.ShowRefreshButton = true;
ReportViewer1.ServerReport.Refresh();
}

This is one of the method to integrate SSRS reports within your asp.net page. You can choose different components in place of the above mentioned.

The XML file used here is a simple one. If one uses complex XML file for the menu, then XPath can be used to retrieve the value from an XMLDocument and bind it to the menu control. The XMLDocument can also be cached using various caching techniques to improve the site performance.

In the above method, clicking on one of the menu items would perform postbacks to the server. This can be avoided with the use of AJAX implementation which would avoid postbacks to the server there by increasing the users experience.

0 comments