1

以下代码在 Asp.net Gridview 控件内的数据第 1 页上效果很好:

     If e.CommandName = "Void" Then

        'Read the status of the ticket currently
        Dim RowIndex As Integer = CInt(e.CommandArgument)
        Dim row As GridViewRow = grdTradeTickets.Rows(RowIndex)

        Dim lblTransactionID As Label = DirectCast(row.FindControl("lblTransactionID"), Label)
        Dim lblTtStatus As Label = DirectCast(row.FindControl("lblTtStatus"), Label)
        Dim lblTradeTicketID As Label = DirectCast(row.FindControl("lblTradeTicketID"), Label)

        'If already void, show "Already Void" message to user. Else continue "Are you sure you want to void this Trade Ticket?"
        If lblTtStatus.Text = "Void" Then

            mdlPopupAlready.show()

        Else

            mdlPopup.Show()
            lblTradeTicketIdToVoid.Text = lblTradeTicketID.Text

        End If

    End If

但是,如果用户在任何后续页面上单击“无效”按钮,则会引发以下错误:

“索引超出范围。必须为非负数且小于集合的大小。参数名称:索引”

它不像索引是空的或什么的。它有一个价值。想法?

4

2 回答 2

0

尝试替换行:

Dim RowIndex As Integer = CInt(e.CommandArgument)
Dim row As GridViewRow = grdTradeTickets.Rows(RowIndex)

Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).Parent.Parent, GridViewRow)
于 2009-04-15T13:38:21.043 回答
0

我面临着同样的问题。然后原来是 SubString() 方法的问题。我在做什么我正在使用索引从字符串中获取子字符串。像

myString.SubString(3, 6);

在 myString 中,我传递的“abc”表示长度为 3 的字符串。查找一些使用子字符串或集合的代码并尝试调试它。干杯:)

于 2012-09-12T10:03:02.880 回答