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

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

Last post 02-06-2009 10:43 by Irman. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-31-2008 10:05

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

    rekan2,

    saya memiliki satu gridview dengan beberapa button di dalamnya. pada saat meng "klik"button pertama (view) pesan error tidka muncul, namun ketika button kedua (approval) error tersebut muncul.

    berikut source error :

    Source Error:

    Line 50:                 'Dim row As GridViewRow = gvSOLeaveIP.Rows(e.CommandArgument)
    Line 51: Dim index As Integer = Convert.ToInt32(e.CommandArgument)
    Line 52: Dim row As GridViewRow = gvSOLeaveIP.Rows(index)
    Line 53: Dim obj As New LeaveWeb
    Line 54: Dim objEISDetail As New clsBusinessEis

     

    berikut scriptnya :

    Protected Sub gvSOLeaveIP_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvSOLeaveIP.RowCommand
            'Dim row As GridViewRow = gvSOLeaveIP.Rows(e.CommandArgument)
            Select Case e.CommandName
                Case "btnView"
                    Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                    Dim row As GridViewRow = gvSOLeaveIP.Rows(index)
                    Session("lrid") = row.Cells(1).Text
                    Session("iType") = 1
                    'Response.Redirect("view_leave.aspx")
                    Dim _URL As String
                    Dim JavaScript As String
                    _URL = "view_leave.aspx"
                    JavaScript = "window.open('" + _URL + "', null, 'resizable=yes,height=700,width=700, left=(screen.availWidth-700)/2, top=(screen.availHeight-600)/2, status=yes,toolbar=no,menubar=no')"
                    Response.Write("<SCRIPT LANGUAGE=javascript>" & vbCrLf)
                    Response.Write("<!--" & vbCrLf)
                    Response.Write(JavaScript & vbCrLf)
                    Response.Write("//-->" & vbCrLf)
                    Response.Write("</SCRIPT>" & vbCrLf)
                Case "cmdprv"
                    'Dim row As GridViewRow = gvSOLeaveIP.Rows(e.CommandArgument)
                    Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                    Dim row As GridViewRow = gvSOLeaveIP.Rows(index)
                    Dim obj As New LeaveWeb
                    Dim objEISDetail As New clsBusinessEis
                    Dim dr As SqlDataReader
                    Dim dra As SqlDataReader

                    obj.eno = row.Cells(2).Text
                    obj.fda = row.Cells(5).Text
                    obj.fdw = row.Cells(6).Text
                    obj.lrid = row.Cells(1).Text
                    obj.stt = 1

                    dr = objEISDetail.InsertLeave(obj)
                    dra = objEISDetail.UpdateLeaveStatus(obj)

                    gvSOLeaveIP.DataBind()
            End Select
        End Sub

     mohon bantuan dari rekan2.

    terima kasih

    Filed under:
    • Post Points: 35
  • 12-31-2008 17:41 In reply to

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

     Kalau dilihat dari error sih mas ya jumlah dari data index yang dipilih tidak sesuai dengan data yang sebenarnya, atau sederhananya menanggil collection pada index ke 1 tetapi anda hanya mempunyai data 1 buah. Pasti akan memunculkan error seperti itu. Hal itu bisa dimungkinkan anda memanggil nilai pada sebuah index pada grid dimana grid tersebut belum di bind dengan sebuah data, coba di debug deh pada   Case "cmdprv" (ini case untuk proses approval kan ?)

    • Post Points: 20
  • 12-31-2008 21:00 In reply to

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

    Atau mungkin bisa jadi line code ini:

    Dim index As Integer = Convert.ToInt32(e.CommandArgument)

    menghasilkan nilai -1 (minus satu)

    Ferry Meidianto
    My Site :: My Blog @ INDC
    • Post Points: 20
  • 01-02-2009 9:46 In reply to

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

    maaf, saya nubie di asp.net

    kalau memang seperti itu kasusnya, solusinya seperti apa ?

    apakah saya harus rubah coding saya ? atau apakah tidak tepat menggunakan row command pada gridview apabila saya hendak menggunakan button field lebih dari satu ?

    mohon pencerahannya.

     

    Terima kasih,

    • Post Points: 20
  • 01-30-2009 10:50 In reply to

    • Suharmin
    • Top 500 Contributor
    • Joined on 12-23-2008
    • Posts 11
    • Points 185

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

     @bocahbetawi

     Coba saja di debug codenya. Liat Indexnya dapat berapa nilainya. Kemudian Coba bandingkan dengan Banyaknya Row yang ditampilkan oleh GridView tersebut. 

    • Post Points: 5
  • 02-06-2009 10:43 In reply to

    • Irman
    • Top 150 Contributor
    • Joined on 02-05-2009
    • Palembang
    • Posts 29
    • Points 400

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

     Jumlah index atau no urut index tidak berada dalam range rows

    trim's

    Iherdiana@telpp.com

    irman.herdiana@live.com
    • Post Points: 5
Page 1 of 1 (6 items)