?
Solved

[C#] Counting an displaying querystring values with same variable name.

Posted on 2005-02-24
9
Medium Priority
?
467 Views
Last Modified: 2008-01-09
Let's say I have a URL like this:
http://localhost/myfile.aspx?report=test.rpt&parm=123&parm=456&parm=606

I need the C# code to loop through the "parm" variables and display their values.  I've tried things like:

foreach(Object o in Request.QueryString["parm"]) Response.Write(o.ToString() + "<br>");
...and...
for(int i=0; i < Request.QueryString["parm"].Count; i++) Response.Write(Request.QueryString["parm"][i] + "<br>");

But neither method works.
0
Comment
Question by:hendridm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 15

Expert Comment

by:praneetha
ID: 13395221
foreach( string s in Request.QueryString)
                        {
Request.QueryString[s].ToString()
}
0
 
LVL 8

Author Comment

by:hendridm
ID: 13395259
Thanks, but that will keep the "parm" values in a comma-separated string, like so:
test.rpt
123,456,606

I'd like to loop through the values within the "parms" object.  I don't want to split by comma either, because the values may contain commas.
0
 
LVL 15

Expert Comment

by:praneetha
ID: 13395285
i am sure it will still work...did u try with , in value
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:hendridm
ID: 13395382
Well, it works in that it adds a comma to the string, however, how do I separate the values?  I can't split on comma because the comma could be the delimiter or a comma in the string value.  I want to be able to display each "parm" value separately, not as one long string.
0
 
LVL 15

Expert Comment

by:praneetha
ID: 13395422
foreach( string s in Request.QueryString)
                    {
Response.Write(Request.QueryString[s].ToString()+"<br>");
}

what do u mean not as one long string...it does display each parm value differently...goes into foreach loop as many times as they r query string available..i am sorry  i do not understand the question right i guess...
0
 
LVL 8

Author Comment

by:hendridm
ID: 13395460
Ok, when I use that code:
foreach(String s in Request.QueryString) {
      Response.Write(Request.QueryString[s] + "<br>");
}

With the following paramenters:
http://localhost/myfile.aspx?report=test.rpt&parm=123&parm=XYZ&parm=606&stuff=something

This is the output:
test.rpt
123,XYZ,606
something

Notice it is concatenating the "parm" values into one long string instead of individual strings/lines?
0
 
LVL 15

Expert Comment

by:praneetha
ID: 13395471
foreach(String s in Request.QueryString) {
Response.Write(s);
     Response.Write(Request.QueryString[s] + "<br>");
}

i guess when s="parm"

and when u say Request.Querystring["parm"]...it's going to return all 3 values...hmmmbut why have same key in a query string...any reason

0
 
LVL 12

Accepted Solution

by:
laotzi2000 earned 900 total points
ID: 13395509
try this one:

for(int i=0; i < Request.QueryString.GetValues(“param").Count; i++) Response.Write(Request.QueryString.GetValues("param")[i] + "<br>");


0
 
LVL 8

Author Comment

by:hendridm
ID: 13395558
Thanks, that did it!  Except it was .Length instead of .Count.  Much appreciated.
for(int i=0; i < Request.QueryString.GetValues("parm").Length; i++) Response.Write(Request.QueryString.GetValues("parm")[i] + "<br>");
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question