Request.QueryString looping....easy question...

D

Doug

I need to do the following...

FOR myitem IN Request.Querystring
'get the key
'get the value
NEXT

What do I DIM myitem as? DictionaryEntry doesn't work...or do I have to
loop through it by index and get the key then the item out of the query
string...

thanks
Doug
 
D

Doug

Lenn,
Tried that and I checked the type and it came back as string....basicly
just the key names that are part of my querystring....

Doug
 
D

Doug

Thanks Justin...but this still requires me to give an index or a name to the
collection object....

dim myitem as NameValueCollection
dim sKey as string
Dim sValue as string
for each myitem in Request.QueryString
'here item needs an index/name...
sKey = myitem.item(some index or name)
next

I thought there was a way to iterate through the querystring collection
without having a counter....using for each then
sKey = myitem.key
sValue = myitem.value
etc...

thanks
Doug
 
S

S. Justin Gengo

Doug,

No, then you can loop through the keys...

Dim Value As String

For Each Item As System.Collections.Specialized.NameValueCollection In
Request.QueryString

For Each Key As String In Item.AllKeys

Value = Item.Get(Key)

Next

Next


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo

Doug,

Don't know what I was thinking when I typed out that code. (The code works
fine) I should have used the variable name "Collection" instead of "Item".

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo

And Geez, now that I test the code out why not just cut right to the chase
and simplify like this:

Dim Value As String

For Each Item As String In Request.QueryString.AllKeys

Value = Item.Get(Key)

Next



Sorry, it took me so long to get to the correct code for you.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo

Doug,

Man, I need some rest. See what staying up till 2:00am drinking mountain dew
and coding can do to you!

The code with the two for nexts was the right way.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo

Doug,

I've splashed some cold water on my face and going for a record number of
posts by one person on the same topic here is the code you need:


Dim Value As String

For Each Key As String In Request.QueryString.AllKeys

Value = Request.QueryString(Key)

Next




--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
D

Doug

Thanks Justin....I'm feeling the same...too much work not enough
sleep...thanks for the replys...

Doug
 
Joined
Dec 5, 2008
Messages
1
Reaction score
0
This post is a bit old but I thought I would put the correct answer in here.
This is how you get the name and value from a Request.QueryString collection (and most other collections). This also gets around the problem of setting colQueryString = Request.QueryString that leaves colQueryString ReadOnly since Request.QueryString is read only.


Dim colQueryString As New Collections.Specialized.NameValueCollection
Dim rqcnt As Int32 = 0
Dim tempName As String
Dim tempValue As String

For rqcnt = 0 To Request.QueryString.Count - 1
'clearing out previous results
tempName = ""
tempValue = ""

'setting name and value for each pair
tempName = Request.QueryString.GetKey(rqcnt)
tempValue = Request.QueryString.Get(rqcnt)

'Adding the result to the a new collection (that is not read only)
colQueryString.Add(tempName, tempValue)
Next

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top