In this article I will explain How to add SSRS
Reports in ASP.NET with Parameters
First you need to develop a SSRS Report, After Open
your web application and add new aspx page. Add below lines of code in your
web.config file.
Add Report server url, Report server folder, Domain
Name, User Name, Password. Follow below steps.
<appSettings>
<add key="ReportServerUrl" value="http://Localhost/ReportServer" />
<add key="ReportServerFolder" value="/Newforler" />
<add key="User" value="Domine Name\ User Name"
/>
<add key="Password" value="Password" />
</appSettings>
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
validate="false" />
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>
</compilation>
ASPX
Page code: Add below
assembly in your ASPX Page.
<%@
Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb1"
%>
Below is the Report design code.
<table
border="0"
cellpadding="0"
cellspacing="0"
width="100%"
bgcolor="white">
<tr>
<td width="20%">
<asp:DropDownList runat="server"
ID="ddlService"
AutoPostBack="true"
Width="180px"
>
</asp:DropDownList>
</td>
</tr>
</table>
<table
border="0"
cellpadding="0"
cellspacing="0"
width="100%"
bgcolor="white">
<tr>
<td width="20%">
</td>
<td align="center" width="80%" valign="top">
<rsweb1:ReportViewer ID="rptView" runat="server" Visible="false" Width="950px" Height="950px"
ShowPrintButton="false" ShowToolBar="false">
</rsweb1:ReportViewer>
</td>
<td width="20%">
</td>
</tr>
</table>
C# Code :
Add below namespaces in aspx.cs page.
using
System.Web.Configuration;
using
Microsoft.Reporting.WebForms;
using System.Xml;
using
System.Web.UI.HtmlControls;
using
System.Diagnostics;
using
System.Configuration;
using System.Net;
Add below lines of code in Page load or Method.
string userName = WebConfigurationManager.AppSettings["User"];
string
passWord = WebConfigurationManager.AppSettings["Password"];
this.rptView.ProcessingMode
= ProcessingMode.Remote;
this.rptView.ShowParameterPrompts
= false;
this.rptView.ServerReport.ReportServerUrl
= new Uri(WebConfigurationManager.AppSettings["ReportServerUrl"].ToString());
IReportServerCredentials
credentials = new CustomReportCredentials(userName,
passWord);
this.rptView.ServerReport.ReportServerCredentials
= credentials;
this.rptView.ServerReport.ReportPath
= WebConfigurationManager.AppSettings["ReportServerFolder"].ToString() + "/ReportName";
System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter> paramlist = new System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter>();
if
(ddlService.SelectedIndex == -1 || ddlService.SelectedIndex == 0)
{
paramlist.Add(new Microsoft.Reporting.WebForms.ReportParameter("Service",
"0"));
}
else
{
paramlist.Add(new Microsoft.Reporting.WebForms.ReportParameter("Service",
ddlService.SelectedValue.ToString()));
}
rptView.ServerReport.SetParameters(paramlist);
this.rptView.ServerReport.Refresh();
this.rptView.Visible
= true;
No comments:
Post a Comment