Beginner
Beginner

Reputation: 29543

vb.net looping through several passed parameters with same name

i am passing paramters from one page to another all witht he same name...how do i look through them?

dim sHtmlBody
sHtmlBody = ""
for i=0 to Request.QueryString("name").Count

sHtmlBody = "<html><body onload=""window.print();"">"
sHtmlBody = sHtmlBody & "<body>hello</body>"
sHtmlBody = sHtmlBody & "</head>"

next

context.Response.Write(sHtmlBody)

this is what i am doing and it works. But how do i access the individual name

Dim Name =  Request.QueryString("Name")(i)

does not work

Upvotes: 0

Views: 534

Answers (2)

scartag
scartag

Reputation: 17680

You could try the following.

dim sHtmlBody
sHtmlBody = ""
Dim nameValues As String = Request.Form.GetValues("name")

For Each name As var In nameValues

sHtmlBody = "<html><body onload=""window.print();"">"
sHtmlBody = sHtmlBody & "<body>hello</body>"
sHtmlBody = sHtmlBody & "</head>"

Next

Which means you can do the following.

Dim name = Request.Form.GetValues("name")(1)

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038810

Assuming the request looks like this: SomePage.aspx?name=name1&name=name2&name=name3 you could split the Name request parameter by comma:

Dim names = Request.QueryString("Name").Split(",")
For Each name As String In names
    ' do something with each name
Next

Upvotes: 0

Related Questions