Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends,

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:
C#
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);


An alternative to using a comma delimited parameter is reusing the same parameter like: www.test.com/?pm1=test1&pm1=test2&pm1=test3.
But this approach is not acceptable by the business and would like to have ability to separate values by coma itself.

Please help, thanks much in advance:)
Posted
Updated 27-Oct-14 6:19am
v3

To do this, you actually add the report parameter again with the same name and a new value. You don't need to try and combine the values.

Just keep adding the same parameter name over and over with the different values.
 
Share this answer
 
Comments
Joy1979 27-Oct-14 12:16pm    
Thanks RyanDev for your reply. I agree that an alternative to using a comma delimited parameter is reusing the same parameter like: www.test.com/?pm1=test1&pm1=test2&pm1=test3.
But this approach is not acceptable by the business and would like to have ability to seperate values by coma itself.
ZurdoDev 27-Oct-14 12:20pm    
Sorry I wasn't clear. Not query string parameters, but ReportParameters.
...
pb1.Name = "PurchaseMaterial";
pb1.Value = "Test1";
...
pb1 = new ReportParameter();
pb1.Name = "PurchaseMaterial";
pb1.Value = "Test2";
Joy1979 27-Oct-14 14:18pm    
Hi, I tried adding report parameter over and over with different values but no luck.
ZurdoDev 27-Oct-14 15:19pm    
Perhaps post your code. This is the right way to do it. You can try it as an array as well, http://stackoverflow.com/questions/18002218/how-to-pass-multi-value-parameter-to-ssrs-from-asp-net-c
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 :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900