sqlserver 2005 中提供了2个webpart可以直接装载report,但是仅限于完成的report并且不能给report传递任何过滤参数。
网上也有好多自定义report webpart.下面是一个代码段可以作为参考。
ReportExecutionService rs = new ReportExecutionService();rs.Credentials =
new System.Net.NetworkCredential(username,password, domain);//一般会用default的那个验证方式。在特殊情况下用这个。rs.Url = ReportServiceUrl;
// Render arguments byte[] result = null; string reportPath = ReportPath; string format = "HTML4.0"; string historyID = null; string devInfo = @"<DeviceInfo><Toolbar>True</Toolbar></DeviceInfo>"; //// Prepare report parameter. //ParameterValue[] parameters = new ParameterValue[3]; //parameters[0] = new ParameterValue(); //parameters[0].Name = "ContractId"; //parameters[0].Value = "288"; //parameters[1] = new ParameterValue(); //parameters[1].Name = "TowerId"; //parameters[1].Value = "6"; // June //parameters[2] = new ParameterValue(); //parameters[2].Name = "ProcessId"; //parameters[2].Value = "20"; DataSourceCredentials[] credentials = null; string showHideToggle = null; string encoding; string mimeType; string extension; Warning[] warnings = null; ParameterValue[] reportHistoryParameters = null; string[] streamIDs = null; ExecutionInfo execInfo = new ExecutionInfo(); ExecutionHeader execHeader = new ExecutionHeader();rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
String SessionId = rs.ExecutionHeaderValue.ExecutionID; try{
result = rs.Render(format, devInfo,
out extension, out encoding, out mimeType, out warnings, out streamIDs);execInfo = rs.GetExecutionInfo();
rs.AllowAutoRedirect =
false;}
catch (SoapException ex1){
writer.Write(ex1.Detail.OuterXml);
}
try{
string htmlResult = System.Text.Encoding.UTF8.GetString(result);writer.Write(htmlResult);
}
catch (Exception ex2){
writer.Write(ex2.Message);
}
可以展现Report, 不过有个问题会产生,就是当生成的report中,含有expand功能的话,点击查看detail会替换当前页为report所在服务器浏览报表窗体。
这个问题一直没想到什么好的方法去处理,网上说用IFRAME,但是放到webpart里的话,IFrame的src是一个静态的url,不能传递参数。。。如果有好方法可以给我留言。
目前这边我是没想到什么好的方法去处理,不过美国那边已经给了相应的处理方式,等完成这部分我会把处理方式发上来。