advertisement

Search | Recent | Register

Forum => General ASP.NET => Iterate through QueryString collection

Jump to:

Next Oldest | Next Newest

2/21/2005 2:20:43 PM Link | Reply | Edit | Quote

CactusJuice

Profile Send Private Message Web Site
Location: Phoenix, AZ | Joined: 9/5/2004 | Posts: 107 | Offline

According to the .NET Frameword docs this is how they loop to get all the QueryStrings for a page. But it seems rather verbose. Does anyone know...can this be done with foreach or something cleaner that doesn't involve a nested loop?

int loop1, loop2;

// Load NameValueCollection object.
NameValueCollection coll=Request.QueryString;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 ");
String[] arr2 = coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 ");
}
}


[/loop1]

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dndotnet/html/csharpsqlxmlhttp.htm

2/21/2005 2:58:10 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 814 | Offline

The QueryString property is a NameValueCollection object, so you could use something like...

foreach (string key in Request.QueryString.Keys)
{
Trace.Warn(Request.QueryString[key]);
}

I haven't tested that, just a logical guess.


Jeff 'Jones' Putz
POP World Media, LLC

Forum => General ASP.NET => Iterate through QueryString collection