This is a migrated thread and some comments may be shown as answers.

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

2 Answers 356 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Bogdan
Top achievements
Rank 1
Bogdan asked on 30 Jan 2013, 01:33 PM
When I click on  btnAssignId, grdResult has 4 rows, but in debug mode in loop I see 5 iterations and on 5th Exeption throw
at line where I try GetDataKeyValue



Private Sub btnAssignId_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAssignExistingId.Click
  If Not String.IsNullOrEmpty(tbMatlID.SelectedValue) Then
    For Each item As GridItem In grdResult.Items
      If item IsNot Nothing Then
        Dim griddata = CType(item, GridDataItem)
   Dim resultId griddata.GetDataKeyValue("ResultId")
        Update(resultId, tbMatlID.SelectedValue)
      End If 
    Next
  End If
End Sub

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Feb 2013, 12:21 PM
Hello Bogdan,

I have created a sample RadGrid web site to test the described behavior. On my side everything works as expected and the the items collection returns the correct count. Please check out the attached application and let me know about the result.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
William
Top achievements
Rank 1
Iron
answered on 08 Sep 2021, 05:54 AM | edited on 08 Sep 2021, 05:54 AM

In my case, it is because the last page of grid has less items than the page size. For example, if the page size is 10, but the last page only have 5 items. Then it will throw this IndexOutOfRange Exception in method GetDataKeyValue.

I'm lazy, so I just try-catch that line

Eyup
Telerik team
commented on 10 Sep 2021, 08:07 PM

Hi


Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Bogdan
Top achievements
Rank 1
Answers by
Eyup
Telerik team
William
Top achievements
Rank 1
Iron
Share this question
or