Index 0 is not non-negative and below total rows count.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index 0 is not non-negative and below total rows count.

Source Error:

 
Line 228:            With ddlVehicleModel
Line 229:                liListItem = .Items.FindByText(dvCustomer(0).Item("Inv_ID").ToString)
Line 230:                .SelectedIndex = .Items.IndexOf(liListItem)
Line 231:            End With

 

This error occurs when there are no records in the child table that relate to the selected record in the parent table, making the data view empty.  In order to fix this problem, enclose the code in a Try/Catch block, shown below.  Another solution would be to check to see whether or not the data view is empty before searching for any matching records.

 

       Try

           With ddlVehicleModel

              liListItem = .Items.FindByText(dvCustomer(0).Item("Inv_ID").ToString)

              .SelectedIndex = .Items.IndexOf(liListItem)

           End With

       Catch

       End Try