0

我已经非常接近解决我花了几天时间解决的问题。

我正在尝试将参数传递给 ASP.net 页面上的 SSRS 报告。用户在之前的页面上选择 2 个选项,程序(3 个程序的下拉列表)和期间(日期)。

我可以得到一些通过,但不是我想要的。这是用户选择要在报告上显示的内容的页面:

        ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Bill Created!');window.open('../demographics/supbillrpt.aspx?prog=fprogram&period=cperiod','_self');", true);

fprogram 是:

        SqlParameter param2 = new SqlParameter();
        param2 = command.Parameters.Add("@program", SqlDbType.Char);
        param2.Value = fprogram;

cperiod 是一样的,但它是一个日期。

这是显示报告的页面上的代码:

        String sprogram = Request.QueryString[0];
        String speriod = Request.QueryString[1];

        ReportViewer1.ProcessingMode = ProcessingMode.Remote;
        ReportViewer1.Width = 800;
        ReportViewer1.Height = 600;
        IReportServerCredentials irsc = new CustomReportCredentials();
        ReportViewer1.ServerReport.ReportServerCredentials = irsc;
        ReportViewer1.ServerReport.ReportPath = "/sup_billing/Report1";
        ReportViewer1.ServerReport.Refresh();
        ReportParameter p = new ReportParameter("prog", sprogram);                      ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { p });
        ReportParameter p2 = new ReportParameter("period", speriod); ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { p2 });

我得到的是程序是空白的,句号是“cperiod”

我尝试了一些不同的方法来让它作为变量读取,但似乎没有任何效果。

如果我输入以下内容:

ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Bill Created!');window.open('../demographics/supbillrpt.aspx?prog=VEX&period=cperiod','_self'); “, 真的);

VEX 是该下拉列表中的一个项目,并且会显示出来,因为我把它放在那里。但用户不会总是选择 VEX,所以我需要使用 fprogram 变量。有什么建议么?

4

1 回答 1

0

我假设您的第一个代码片段是您正在使用的实际代码,而不是代码一般形式的模型。我进一步假设您有名为fprogramand的变量cperiod

您需要构建查询字符串以反映您希望传递的确切值。不幸的是,您不能对要用作值源的变量的名称进行编码并插入实际值。

所以你的代码应该是这样的:

// I am assuming you're getting your fprogram and cperiod values from controls.  The 
// control names are of course up to you.

string fprogram = ddlProgram.SelectedValue;
string cperiod =  txtPeriod.Text;  // I'm assuming this contains a formatted date.

string queryString = String.Format(
     "../demographics/supbillrpt.aspx?prog={0}&period={1}", 
     fprogram, 
     cperiod);
string script = String.Format(
     "alert('Bill Created!');window.open('{0}','_self');",
     queryString);

ClientScript.RegisterStartupScript(this.GetType(), "Alert", script, true);

希望这可以帮助。

于 2013-02-04T18:28:19.323 回答