2

すべてをチェックしてすべてをチェック解除する機能を備えたグリッドビューのチェックボックスコントロールがあります。

このページはページネーションも使用しています。各ページには 25 のレコードがあります。もちろん、これ以上は次のページに進みます。

ユーザーが 1 つ以上のチェックボックスをオンにすると、ユーザーの選択内容が次のコードを使用して処理されます。

Dim uItems As String = String.Empty 

For Each r As GridViewRow In GridView1.Rows 

    If CType(r.Cells(0).FindControl("recs"), CheckBox).Checked Then 

        If uItems <> String.Empty Then 

            uItems += "," 

        End If 

        uItems += "http://default.html?gen=" & r.Cells(1).Text & "&NO=3&F=1" 

    End If 

Next 

ユーザーが 15 以下をチェックすると、次のようになります。

http://default.html?gen=" & r.Cells(1).Text & "&NO=3&F=1これは、チェックした数だけ取得できるため機能します。

現在発生している問題は、ユーザーが 15 個を超えるチェックボックスをオンにすると、

「Internet Explorer は Web ページを表示できません。できること - 接続を診断してください...」

いくつかのトラブルシューティングを行った結果、セル(1) からそのリンクに 15 を超える値を渡すことができたことが壊れている理由であることがわかりました。

誰もこれに対する回避策を知っていますか?

これは昨日投稿した問題とまったく同じでしたが、説明が間違っていたため、専門家が正しい解決策を提供するのが難しくなっています。

ご協力いただきありがとうございます。

4

4 に答える 4

4

I think it's the same issue I had once: the URL you're building is too long and the request cannot be processed properly.

If you need to send a very long sequence of data in the URL you should switch to a POST request (in place of a GET request), thus removing the data from the querystring

Another option is that you're appending URL parameters with the same key.

于 2012-08-10T14:34:57.413 に答える
2

URL の長さの制限に達している可能性があります (こちらを参照してください- 別のブラウザーを試して確認してください)。各セルから取得するテキストの長さは?

これが問題である場合は、GET (クエリ文字列が行っていること) の代わりに POST をサーバーに送信するか、クエリ文字列を短くする方法を見つけます。

于 2012-08-10T14:34:31.540 に答える
1

投稿したコードを使用して、複数のアイテムをチェックしている場合、URLは次のようになります。

http://default.html?gen=sometext&NO=3&F=1,http://default.html?gen=sometext&NO=3&F=1,http://default.html?gen=sometext&NO=3&F=1

これはあなたが意図したことではないと思います。

試す

Dim uItems As String = String.Empty  

For Each r As GridViewRow In GridView1.Rows  
    If CType(r.Cells(0).FindControl("recs"), CheckBox).Checked Then  
        If uItems <> String.Empty Then  
           uItems += ","  
        End If  
        uItems +=  r.Cells(1).Text  
    End If  
Next  
uItems = "http://default.html?gen=" & uItems & "&NO=3&F=1"

それはもっと似たようなものを返すはずです

http://default.html?gen=sometext,itemblah,moretext&NO=3&F=1

于 2012-08-10T14:37:21.690 に答える
1

長すぎるクエリ文字列を生成していると思われますが、コードには他にも問題があります。StringBuildera を使用して、s の繰り返しインスタンス化を保存するように変更しましたString

Dim uItems As New StringBuilder("http://default.html?gen=")

For Each r As GridViewRow In GridView1.Row
    If CType(r.Cells(0).FindControl("recs"), CheckBox).Checked Then
        uItems.AppendFormat("{0},", r.Cells(1).Text)
    End If
End For

-- Remove trailing delimiter
uItems.Remove(uItems.Length - 1, 1)

uItems.Append("&NO=3&F=1")

このコードを使用uItems.ToString()すると、次のようなものが得られます

http://default.html?gen=bla1,bla2,bla3&NO=3&F=1

あなたは実際にこのようなものが欲しいかもしれません。

Dim uItems As New StringBuilder("http://default.html?")

Dim checkCount = 0
For Each r As GridViewRow In GridView1.Row
    If CType(r.Cells(0).FindControl("recs"), CheckBox).Checked Then
        uItems.AppendFormat("g{0}={1}&", checkCount, r.Cells(1).Text)
        checkCount += 1
    End If
End For

-- Remove trailing delimiter
uItems.Remove(uItems.Length - 1, 1)

uItems.Append("&NO=3&F=1")

これにより、クエリ文字列でチェックされたセルが列挙され、次のようになります。

http://default.html?g1=bla1&g2=bla2&g3=bla3&NO=3&F=1

チェックされたアイテムごとに URL を返すには

Dim urlItems = New List(Of String)()

Const urlFormat As String = _
    "http://default.html?gen={0}&NO=3&F=1"

For Each r As GridViewRow In GridView1.Row
    If CType(r.Cells(0).FindControl("recs"), CheckBox).Checked Then
        Dim url = String.Format(urlFormat, r.Cells(1).Text)
        urlItems.Add(url)
    End If
End For

これによりurlItems、文字列の一般的なリストになり、各項目が URL になります


上記のビットは、URL 文字列のリストを取得する方法を示しているので、URL を反復するには

For Each url As String In urlItems
    //... Some code for POSTing or GETting .. your request 
End For
于 2012-08-10T14:49:27.410 に答える