[thelist] ASP.NET: For Each Item In...

Anthony Baratta anthony at baratta.com
Tue Jul 18 12:30:28 CDT 2006

-----Original message-----
From: "Casey Crookston" caseyc at IntelliSoftmn.com

> I've been using Google to try and figure out how to parse a form . . .
> This code:
> Sub btn_click(ByVal sender As Object, ByVal e As System.EventArgs)
>         Dim item As ListItem
>         For Each item In Request.Form
>             lbl_submit.Text &= item.Text & "<br>"
>         Next
>     End Sub

The form object is a container type "NameValueCollection". You want to iterate over it this way:

            // Convert Request.Form Collection to Hashtable
            HttpContext htc = HttpContext.Current;
            Hashtable htFormData = new Hashtable();
            foreach (string sForm in htc.Request.Form.Keys)
                htFormData[sForm] = htc.Request.Form[sForm].ToString();

I like Hashtables myself, so I just convert it. ;-)

I know you are using VB.net, but this should get you in the right direction. Or look up NameValueCollection in the SDK Help and see what to do with it with VB.net.

More information about the thelist mailing list