惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
G
Google Developers Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
有赞技术团队
有赞技术团队
Vercel News
Vercel News
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
The Cloudflare Blog
B
Blog
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
U
Unit 42
D
Docker
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
A
About on SuperTechFans

博客园 - 蒜头

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for (email address). 再谈Images到xps,pdf的转换 SQL Server 2005中xml类型和函数的简单应用 部分Office 2007文件格式转换为xps和pdf代码整理 Image.FromFile gives "Out of Memory" Exception for icon - 蒜头 简单介绍PDF,XPS,Images,Office 2007之间的转换方法 - 蒜头 - 博客园 SQL 2005 全文检索(续) 简单实现C#生成Excel 2007文件并下载 配置SQL Server Session方法 采用负载均衡,部署了两个ASP.NET 2.0的站点服务器碰到的问题 初试VSTS 2008(TFS安装) Windows Server 2003分区修改方法[转载] 制作VSTO 2005 SE开发的Office 2007 AddIn的安装包 一个简单的document library event handler VS 2005 SP1 安装错误 [续] 一个简单的Checkbox Custom Field Type ASP.NET 2.0 SQL Cache 配置方法 解读Document Library关于权限的对象模型 SharePoint应用AJAX.NET和AJAX Control Toolkit
简单应用ReportViewer控件
蒜头 · 2008-01-28 · via 博客园 - 蒜头

首先,将开发好的report部署到Reporting Service上。

1. 写一个类实现接口Microsoft.Reporting.WebForms.IReportServerCredentials,用于Reporting Service的验证,有1个方法,2个属性,根据运行环境来实现这个接口,我这里使用环境的Web程序,Reporting Service需要Window身份验证:

        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 new NetworkCredential(userName, password, domain);
            }

        }

2. 在页面上添加ReportViewer控件,设置属性:

          <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>

主要的是ProcessingMode="Remote",有两种模式,另外一种是Local。如果是Local,下面就是<LocalReport.....
另外重要的是ReportPath和ReportServerUrl,设置正确。
3. 代码:

        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);
            }

        }

设置验证,report是实现了接口的类的一个实例,

                ReportCredential report = new ReportCredential();
                ctl_rv_Report.ServerReport.ReportServerCredentials 
= report;

添加参数,根据report service里的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);

可以在某个postback后设置参数,比如点击button,dropdownlist selectedindexchanged事件,只有设置了参数后,reportViewer控件才会将RS中的结果显示在页面上了。