クエリ文字列をループして、次のように特定の値を引き出そうとしています:
?ProductID=1234&ProductID=4321&Quantity=1
ProductID の横にある各値に対して、いくつかのロジックを実行したいと考えています。しかし、値に到達する方法がわかりません。何か案は?
クエリ文字列をループして、次のように特定の値を引き出そうとしています:
?ProductID=1234&ProductID=4321&Quantity=1
ProductID の横にある各値に対して、いくつかのロジックを実行したいと考えています。しかし、値に到達する方法がわかりません。何か案は?
クエリ文字列に同じキーを持つ複数の値がある場合、文字列配列を返すNameValueCollection.GetValuesメソッドを使用できます。
dim productID as string
for each productID in Page.Request.QueryString.GetValues("ProductID")
' do something with productID
next productID
以下は、ページ上のコード ビハインドで機能する未テストの疑似コードです。これが役立つことを願っています。
dim key as string
dim list as new arraylist()
for each key in Page.Request.QueryString.Keys
if key = "ProductID" then
list.add(Page.Request.QueryString(key))
end if
next key
' do somthing with the list of product id's
Dim productID = Request.Querystring("ProductID")
Dim quantity = Request.Querystring("Quantity")
Dim sQS as String = Request.QueryString.ToString
For Each eItem In Split(sQS, "&")
Dim sName As String = Left(eItem, InStr(eItem & "=", "=") - 1)
Response.Write(sName _
& " = " & Request.QueryString(sName) _
& "<br>")
Next
これは短いですが、同じ考えに基づいています
For Each Key As String In Request.QueryString.Keys
Response.Write(Key & " = " & Request.QueryString(Key) & "<br>")
Next
これを試してみてください。VB9 でのみ動作します。
Dim queryString = GetQueryString()
queryString = queryString.SubString(1) 'Remove ?
Dim ids = queryString. _
Split("&"c). _
Select(Function(x) x.Split("="c)). _
Where(Function(x) x(0) = "ProductId" ). _
Select(Function(x) x(1))