Please help
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
Protected Sub Studentgrid_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles Studentgrid.RowDataBound
' Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim average As Decimal
If e.Row.RowType = DataControlRowType.DataRow Then
Try
average = Convert.ToDecimal(e.Row.Cells(2).Text)
Catch ex As Exception
Console.WriteLine("{0} Exception caught.", ex)
End Try
Dim index As Integer = Convert.ToInt32(e.Row.RowIndex)
'Dim row As GridViewRow = Studentgrid.Rows(index)
Dim classr As String = Studentgrid.Rows(index).Cells(6).Text
Dim cut As Decimal
Using Con As New SqlConnection(conString)
Con.Open()
Using Com2 As New SqlCommand("SELECT * FROM cutoff WHERE class = '" & classr & "'", Con)
Using RDR2 = Com2.ExecuteReader()
If RDR2.HasRows Then
RDR2.Read()
cut = RDR2.Item("verage").ToString
End If
End Using
End Using
End Using
If average < cut Then
e.Row.Cells(0).Text = "Failed"
e.Row.Cells(0).ForeColor = System.Drawing.Color.Red
Else
e.Row.Cells(0).Text = ""
End If
If average = 0 Then
e.Row.Cells(0).Text = ""
End If
End If
End Sub
<asp:GridView ID="Studentgrid" runat="server" ItemStyle-Width="Auto" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Status" />
<asp:ButtonField CommandName="Select" HeaderText="Payments" Text="Payments" />
<asp:BoundField AccessibleHeaderText="Average" DataField="Average" HeaderText="Average"></asp:BoundField>
<asp:BoundField DataField="account" HeaderText="Admno" SortExpression="account" />
<asp:BoundField DataField="Name" HeaderText="Names" SortExpression="Name" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="intake" HeaderText="Intake" SortExpression="intake" />
<asp:BoundField DataField="amounts" HeaderText="Amount" SortExpression="amount" />
<asp:BoundField DataField="commitment" HeaderText="PayStatus" SortExpression="commitment" />
<asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
</Columns>
</asp:GridView>