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

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] + "'";
                        value += ",'" + strPb1[i] + "'";
                    i += 1;

Please help, thanks much in advance:)

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 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.

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

Solution 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 🙂

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply