First, deploy the developed report to the reporting service.
1. write a class implementation interface Microsoft. reporting. webforms. ireportservercredentials is used for reporting service verification. It has one method and two attributes. This interface is implemented based on the runtime environment. Here I use the Web EnvironmentProgram, Reporting service requires window authentication:
Public Bool Getformscredentials ( Out System. net. Cookie authcookie, Out String Username, Out String Password, Out String Authority)
{
Username = String. empty;
Password = String. empty;
Authority = String. empty;
Authcookie = Null ;
Return False ;
}
Public System. Security. Principal. windowsidentity impersonationuser
{
Get {Return Null;}
}
Public System. net. icredentials networkcredentials
{
Get
{
Return NewNetworkcredential (username, password, domain );
}
}
2. Add the reportviewer control on the page and set the attributes:
< Rsweb: reportviewer ID = "Ctl_rv_report" Runat = "Server" Font-names = "Verdana" Font-size = "8pt"
Height = "400px" Processingmode = "Remote" Showtoolbar = "False" Width = "100%" Asyncrendering = "False" Internalbordercolor = "Transparent" Promptareacollapsed = "True" Showparameterprompts = "False" >
< Serverreport Reportpath = "/Folder/name" Reportserverurl = "Http: // site/reportserver" />
</ Rsweb: reportviewer >
The main mode is processingmode = "remote". There are two modes, and the other is local. If it is local, the following is <localreport .....
In addition, it is important to set reportpath and reportserverurl correctly.
3.Code:
Protected Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
Reportcredential report = New Reportcredential ();
Ctl_rv_report.serverreport.reportservercredentials = Report;
Ilist < Reportparameter > Parms = New List < Reportparameter > ();
Reportparameter P = New Reportparameter ( " Locationslocationid " , " [Locations]. [location id]. & [ " + Locationid + " ] " );
Parms. Add (P );
Ctl_rv_report.serverreport.setparameters (parms );
}
}
Set verification. Report is an instance of the class that implements the interface,
Reportcredential report = New Reportcredential ();
Ctl_rv_report.serverreport.reportservercredentials = Report;
Add parameters according to the report in the report service:
Ilist < Reportparameter > Parms = New List < Reportparameter > ();
Reportparameter P = New Reportparameter ( " Locationslocationid " , " [Locations]. [location id]. & [ " + Locationid + " ] " );
Parms. Add (P );
Ctl_rv_report.serverreport.setparameters (parms );
You can set parameters after a certain PostBack, such as clicking the button and dropdownlist selectedindexchanged event. The reportviewer control displays the RS results on the page only after the parameters are set.