我使用C#创建了一个简单的ASP.NET页面,用户输入参数,点击按钮,SSRS报告在网页中运行并显示。但是,我希望报告在新窗口中打开,而不是嵌入在ASPX页面中。
这是我现在的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
string AccountNumber = AcctNo.Text;
ReportViewer.ProcessingMode = ProcessingMode.Remote;
ReportViewer.ServerReport.ReportServerUrl = new Uri(@"http://johnssrsd04/ReportServer_SSRS2008DEV01");
ReportViewer.ServerReport.ReportPath = "/Client Metrics POC/Reports/ClientMetricsDownload_POC";
ReportViewer.ServerReport.Refresh();
ReportParameter[] reportParameterCollection = new ReportParameter[1]; //Array size describes the number of paramaters.
reportParameterCollection[0] = new ReportParameter();
reportParameterCollection[0].Name = "paraAcctNo"; //Give Your Parameter Name
reportParameterCollection[0].Values.Add(AccountNumber); //Pass Parametrs's value here.
ReportViewer.ServerReport.SetParameters(reportParameterCollection);
ReportViewer.ServerReport.Refresh();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
有没有办法更改它以在新窗口中打开SSRS报告?
答案 0 :(得分:1)
以下是使用JavaScript的方法:
<asp:Button ID="Button2" runat="server" OnClientClick="openReport();" Text="Open Report" />
<script>
function openReport() {
window.open("yourReportPage.aspx");
return false;
}
</script>
将按钮点击代码更改为加载事件。