1

The following code works great on Page 1 of data inside an Asp.net Gridview control:

     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

However if the user clicks the "Void" button on any later page, the following error is thrown:

"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

It's not like the Index is null or something. It has a value. Thoughts?

codethrift
  • 2,337
  • 4
  • 17
  • 16

2 Answers2

0

I was facing the same problem. Then it turned out to be the problem with SubString() Method. What I was doing I was getting the substring from a string using index. Like

myString.SubString(3, 6);

and in myString, I was passing "abc" means the string of length was 3. Look for some code which is using substring or collection and try to debug it. Cheers :)

Usman Khalid
  • 3,032
  • 9
  • 41
  • 66
0

Try replacing the lines:

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

with

Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).Parent.Parent, GridViewRow)
Macros
  • 7,099
  • 2
  • 39
  • 61