有两种方式遍历一个ASP集合中的所有成员,方式与普通VB集合的基本相同。每个集合提供一个Count属性,返回的是集合中条目数量。可通过使用一个整型索引使用Count属性来遍历。
For intLoop=1 To Request.Form.Count
Response.Write Request.Form(intLoop) & “<BR>”
Next
为了能够在这种情况下,访问单个值,可以用复杂一些的代码:
For Each objItem In Request.Form
If Request.Form(objItem).Count >1 Then ‘More than one value in this item Response.Write objItem & “:<BR>”
For intLoop = 1 To Request.Form(objItem).Count
Response.Write “Subkey” & intLoop & “value = “& Request.Form(objItem) (intLoop) & “<BR>”
Next
Else
Response.Write objItem & “ = ” & Request.Form(objItem) & “<BR>”
End If
Next
对于前面的包含三个OtherHobby控件的窗体实例,这将返回:
OtherHobby:
Subkey 1 value = Gardening
Subkey 2 value =
Subkey 3 value = Mountaineering