2011-09-25 46 views
0

我將參數從一個頁面傳遞到另一個,所有的名稱都是同一個名字......我如何查看它們?vb.net通過幾個傳遞的參數同名的循環

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) 

這就是我正在做的,它的工作原理。但這樣做,我怎麼訪問個人名義

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

不起作用

回答

0

假設的要求是這樣的:SomePage.aspx?name=name1&name=name2&name=name3,你可以用逗號分割Name請求參數:

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

你可以試試下列。

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 

這意味着您可以執行以下操作。

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

「1維數組的字符串」類型的值不能轉換爲「字符串」。 – Beginner

+0

@Beginner在什麼時候你得到這個錯誤?第一個代碼塊的單行代碼? – scartag