locked
System.IndexOutOfRangeException: There is no row at position 98. RRS feed

  • Question

  • hi Im try to import data from excel sheet to my sql server database

    I get the following error

    There is no row at position 98.

     

    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: There is no row at position 98.

    Source Error:

    Line 84: 
    Line 85:             For i As Integer = 0 To DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).Items.Count - 1
    Line 86:                 If DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).Items(i).Text.ToLower() = Topic.Tables(0).Rows(k)("TEACHERNAME").ToString().ToLower() Then
    Line 87:                     DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).Items(i).Selected = True
    Line 88:                     i = DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).Items.Count


    Source File: C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\visual studio\cstsWebSetup1\blkinstchtrained.aspx.vb    Line: 86

    Stack Trace:

    the code full code is below

    If

     

    e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem

    Then

     

    'Try

     

    DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).DataSource = DirectCast(ViewState("WTeacher"

    ), DataSet)

     

    DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).DataTextField =

    "TEACHERNAME"

     

    DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).DataValueField =

    "TEACHERID"

     

    DirectCast(e.Item.FindControl("ddlteacher"

    ), DropDownList).DataBind()

     

    For i As Integer = 0 To DirectCast(e.Item.FindControl("ddlteacher"

    ), DropDownList).Items.Count - 1

     

    If DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).Items(i).Text.ToLower() = Topic.Tables(0).Rows(k)("TEACHERNAME").ToString().ToLower()

    Then

     

    DirectCast(e.Item.FindControl("ddlteacher"), DropDownList).Items(i).Selected =

    True

    i =

    DirectCast(e.Item.FindControl("ddlteacher"

    ), DropDownList).Items.Count

     

    End

    If

     

    Next

     

    DirectCast(e.Item.FindControl("ddltrtype"), DropDownList).DataSource = DirectCast(ViewState("Typetraining"

    ), DataSet)

     

    DirectCast(e.Item.FindControl("ddltrtype"), DropDownList).DataTextField =

    "Coursename"

     

    DirectCast(e.Item.FindControl("ddltrtype"), DropDownList).DataValueField =

    "trcrseid"

     

    DirectCast(e.Item.FindControl("ddltrtype"

    ), DropDownList).DataBind()

     

    For i As Integer = 0 To DirectCast(e.Item.FindControl("ddltrtype"

    ), DropDownList).Items.Count - 1

     

    If DirectCast(e.Item.FindControl("ddltrtype"), DropDownList).Items(i).Text.ToLower() = Topic.Tables(0).Rows(k)("Typetraining").ToString().ToLower()

    Then

     

    DirectCast(e.Item.FindControl("ddltrtype"), DropDownList).Items(i).Selected =

    True

    i =

    DirectCast(e.Item.FindControl("ddltrtype"

    ), DropDownList).Items.Count

     

    End

    If

     

    Next

     

    If DirectCast(e.Item.FindControl("lblcert"), Label).Text = "YES"

    Then

     

    DirectCast(e.Item.FindControl("ddlcert"), DropDownList).SelectedValue =

    "YES"

     

    ElseIf DirectCast(e.Item.FindControl("lblcert"), Label).Text = "NO"

    Then

     

    DirectCast(e.Item.FindControl("ddlcert"), DropDownList).SelectedValue =

    "NO"

     

    End

    If

     

    If DirectCast(e.Item.FindControl("lbltshirt"), Label).Text = "YES"

    Then

     

    DirectCast(e.Item.FindControl("ddltshirt"), DropDownList).SelectedValue =

    "YES"

     

    ElseIf DirectCast(e.Item.FindControl("lbltshirt"), Label).Text = "NO"

    Then

     

    DirectCast(e.Item.FindControl("ddltshirt"), DropDownList).SelectedValue =

    "NO"

     

    End

    If

     

    If DirectCast(e.Item.FindControl("lblallw"), Label).Text = "YES"

    Then

     

    DirectCast(e.Item.FindControl("ddlallw"), DropDownList).SelectedValue =

    "YES"

     

    ElseIf DirectCast(e.Item.FindControl("lblallw"), Label).Text = "NO"

    Then

     

    DirectCast(e.Item.FindControl("ddlallw"), DropDownList).SelectedValue =

    "NO"

     

    End

    If

    k += 1

     

    'Catch ex As Exception

     

    ' MsgBox(ex.Message)

     

    'End Try

     

    End

    If

    • Moved by Mark Liu-lxf Tuesday, November 1, 2011 6:02 AM ASP.net (From:Visual Basic General)
    Thursday, October 27, 2011 11:07 AM

Answers

All replies