Unable to pass multiple values in querystring in .aspx to report at runtime

喜欢而已 提交于 2019-12-04 06:19:27

问题


This should be simple process but now it became annoying issue.

I am trying to pass multiple value in query string in my ASP.Net web report in VS2012. The page has to pass multiple values to the report as a parameter . When I sent a single value (for eg: abc,) the data is being pulled up correctly but however when I am passing multiple values separated by a comma (eg abc,xyz) it is not displaying the results These multiple values separated by a comma are being passed to the page as query strings and we then are reading them and passing it to the report.

Please note:

For the parameter in the report, I set the default list of values and I also defined available set of values. Now when I am trying to trying pass the values to this parameter from c# code, it is still not accepting the values that I supplied instead it is taking all the values from available list. I think the problem is that the SSRS is not accepting values separated by a comma when "Allow multiple values" check box is checked. Please advise.

This is what I am trying so far:

  ReportParameter pb1 = new ReportParameter();
        if (!string.IsNullOrEmpty(Request.QueryString["pm1"])) { 
            pb1.Name = "PurchaseMaterial1";
            string[] strPb1 = Server.UrlDecode(Request.QueryString["pm1"]).Split(',');
            string value = Server.UrlDecode(Request.QueryString["pm1"]);
            if (strPb1.Length > 0)
            {
                int i = 0;
                value = "";
                while (i < strPb1.Length)
                {
                    if (value == string.Empty)
                    {
                        value = "'" + strPb1[i] + "'";
                    }
                    else
                    {
                        value += ",'" + strPb1[i] + "'";
                    }
                    i += 1;
                }
            }
            pb1.Values.Clear();
            pb1.Values.Add(value);

Please help, thanks much in advance:)


回答1:


strPb1.Length will always be greater than 0 in your code. If there are no commas Split(',') will still return an array containing the original string. Therefore, your initial setting of value isn't necessary.

The QueryString and split() itself seem to be fine. Perhaps the problem lies elsewhere in your code or the querystring you're using. If you're going to add the commas back into your string, why remove them?

Also, An alternative to using a comma delimited parameter is reusing the same parameter. www.test.com/?pm1=test1&pm1=test2&pm1=test3

string[] strPb1 = Request.QueryString.GetValues("pm1");
if(strPb1 != null && strPb1.Length > 0)
{
    for(int i = 0; i != strPb1.Length; i++)
    {
        //Code here
    }
}



回答2:


Thank you for your time and valuable inputs. I tried different approach but was not accepting the values that we are passing from the code.

Since the report is not accepting the multi-value Parameter values via code, I added another parameter in report which is set to null by default. Via code, I am passing the values to this parameter. if the value is present then we are ignoring the values from the multi dropdown parameter "pb1". With this approach we are able to pass multiple values via query string for Pb1 and/or Pb2 but the only downside is that now we have a new parameter in report.

I am not in favor of this new dummy parameter approach but in past 2-3 days I tried my best to pass multiple values to the parameter in the dropdown list via code but somehow did not work. It should be a simple process. This is very baffling but I will get to the bottom of this. Meanwhile I can use current approach.

Again thanks much for all your efforts :)



来源:https://stackoverflow.com/questions/26552587/unable-to-pass-multiple-values-in-querystring-in-aspx-to-report-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!