Index was out of range. Must be non-negative and less than the size of the collection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seep
    New Member
    • Aug 2007
    • 15

    Index was out of range. Must be non-negative and less than the size of the collection

    hi to all.

    i m finding this exception in the following code but unable to understand ..

    Code:
    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
           [B] Dim opd_sr As Integer = CInt(Gridview1.DataKeys(e.RowIndex).Value.ToString)[/B]       
            outTicketDetail.DeleteCommand = "Delete"
            outTicketDetail.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure
            outTicketDetail.DeleteParameters.Add("@opd_sr", TypeCode.Int32, opd_sr.ToString())
            'outTicketDetail.Delete()
          opd_sr.ToString
    
        End Sub
    at bold line i find error.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    What does Gridview1.DataK eys(e.RowIndex) .Value.ToString return?

    Comment

    • seep
      New Member
      • Aug 2007
      • 15

      #3
      it should return the primary key of that row i.e opd_sr. but at this point i m finding exception of "Index was out of range. Must be non-negative and less than the size of the collection."

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        I notice you said should, what debugging have you tried?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by kenobewan
          What does Gridview1.DataK eys(e.RowIndex) .Value.ToString return?
          I'd be interested in knowing the size of DataKeys vs the size of e.RowIndex.
          If you could print those before the guilty statement is reached ...

          Comment

          Working...