0

VS2010 と VB.net 2.0 を使用しています。オンラインで見つけたコードを修正して、グリッドビューを一括更新できるようにしました。gridview のデータキーはオペレーター番号 (変数 currentID によって参照される) であり、そのほとんどは 3 桁ですが、一部は 4 桁です。このコードは、4 桁のオペレーター番号を持つ行を除いて、うまく機能します。4 桁の演算子番号は、次のステートメントに到達すると、Index was outside of the bounds of the array のエラーを返します。

Dim gvMgr_row As System.Data.DataRow = gvMgr_originalDataTable.Select(String.Format("op_num = {0}", currentID))(0)

4 桁で問題が発生する理由を特定できませんでした。助けやアドバイスをいただければ幸いです。関連するすべてのコードを以下に含める必要があります。

Protected Sub MgrUpdateButton_Click(sender As Object, e As System.EventArgs) Handles MgrUpdateButton.Click
    gvMgr_originalDataTable = CType(ViewState("gvMgr_originalValuesDataTable"), System.Data.DataTable)

    For Each r As GridViewRow In gvMgrData.Rows
        If gvMgr_IsRowModified(r) Then gvMgrData.UpdateRow(r.RowIndex, False)
    Next

    ' Rebind the Grid to repopulate the original values table.
    gvMgr_tableCopied = False
    gvMgrData.DataBind()
End Sub

Protected Function gvMgr_IsRowModified(ByVal r As GridViewRow) As Boolean
    Dim currentID As Integer
    Dim currentThreshold1 As String
    Dim currentPayout1 As String
    Dim currentThreshold2 As String
    Dim currentPayout2 As String
    Dim currentThreshold3 As String
    Dim currentPayout3 As String
    Dim currentThreshold4 As String
    Dim currentPayout4 As String

    currentID = Convert.ToInt32(gvMgrData.DataKeys(r.RowIndex).Value)

    currentThreshold1 = CType(r.FindControl("Threshold1TextBox"), TextBox).Text
    currentPayout1 = CType(r.FindControl("Payout1TextBox"), TextBox).Text
    currentThreshold2 = CType(r.FindControl("Threshold2TextBox"), TextBox).Text
    currentPayout2 = CType(r.FindControl("Payout2TextBox"), TextBox).Text
    currentThreshold3 = CType(r.FindControl("Threshold3TextBox"), TextBox).Text
    currentPayout3 = CType(r.FindControl("Payout3TextBox"), TextBox).Text
    currentThreshold4 = CType(r.FindControl("Threshold4TextBox"), TextBox).Text
    currentPayout4 = CType(r.FindControl("Payout4TextBox"), TextBox).Text

    Dim gvMgr_row As System.Data.DataRow = gvMgr_originalDataTable.Select(String.Format("op_num = {0}", currentID))(0)

    If Not currentThreshold1.Equals(gvMgr_row("Threshold1").ToString()) Then Return True
    If Not currentPayout1.Equals(gvMgr_row("Payout1").ToString()) Then Return True
    If Not currentThreshold2.Equals(gvMgr_row("Threshold2").ToString()) Then Return True
    If Not currentPayout2.Equals(gvMgr_row("Payout2").ToString()) Then Return True
    If Not currentThreshold3.Equals(gvMgr_row("Threshold3").ToString()) Then Return True
    If Not currentPayout3.Equals(gvMgr_row("Payout3").ToString()) Then Return True
    If Not currentThreshold4.Equals(gvMgr_row("Threshold4").ToString()) Then Return True
    If Not currentPayout4.Equals(gvMgr_row("Payout4").ToString()) Then Return True

    Return False
End Function
4

0 に答える 0