简体   繁体   English

在ASP.net页上的SSRS报告中正确传递我的参数

[英]Properly passing my parameters in SSRS report on ASP.net page

I'm pretty close to figuring out an issue I've spent days on. 我几乎要弄清楚我花了几天时间解决的问题。

I'm trying to pass parameters to a SSRS report on an ASP.net page. 我正在尝试将参数传递给ASP.net页上的SSRS报告。 The user selects 2 options on the page before, the program (drop down list of 3 programs) and the period (date). 用户在之前的页面上选择2个选项,即程序(3个程序的下拉列表)和时间段(日期)。

I can get something to pass but not what I want. 我可以通过一些事情,但不能实现我想要的。 Here's the page where the user chooses what to display on the report: 这是用户选择在报表上显示内容的页面:

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

fprogram is: fprogram是:

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

cperiod is the same thing but it is a date. cperiod是同一件事,但它是一个约会。

Here's the code behind on the page that displays the report: 这是显示报告的页面上后面的代码:

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

And what I get is the program being blank and the period says "cperiod" 我得到的是程序空白,句点显示“ cperiod”

I've tried a few different things to get it to read it as a variable but nothing seems to be working. 我尝试了一些其他方法来将其读取为变量,但似乎没有任何效果。

IF I put the following in: 如果我输入以下内容:

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

VEX is an item on that dropdown list and will show up because I put it there like that. VEX是该下拉列表中的一项,并且会显示出来,因为我将其放在此处。 But the user won't always select VEX so I need to use the fprogram variable. 但是用户不会总是选择VEX,因此我需要使用fprogram变量。 Any suggestions? 有什么建议么?

I'm assuming your first code fragment is the actual code you're using, rather than a mock-up of the general form of the code. 我假设您的第一个代码片段是您正在使用的实际代码,而不是该代码的一般形式的模型。 I am further assuming that you have variables called fprogram and cperiod . 我进一步假设您具有称为fprogramcperiod变量。

You need to build your query string to reflect the exact values you wish to pass. 您需要构建查询字符串以反映您希望传递的确切值。 You cannot, unfortunately, code the name of the variable you want to use as the source of the value and have the actual value be inserted. 不幸的是,您不能对要用作值源的变量名进行编码,而不能插入实际值。

So your code should look something like this: 因此,您的代码应如下所示:

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM