Simple application of the reportviewer Control

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.