Link to home
Start Free TrialLog in
Avatar of Sreekanth_Nagabandi
Sreekanth_Nagabandi

asked on

Index was out of range

Hi,

I am getting an error message at the following line. Please look at the following line in the below method and resolve the error.

AlarmView.Nodes.Item(1).Text = CInt(txt_max_value.Text)


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


Protected Sub but_update_condition_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles but_update_condition.Click
        ConnectToDb()

        Dim sel_node As String
        Dim con_id As Integer
        Dim min_value As Integer
        Dim max_value As Integer
        Dim signal_id As String
        Dim alarm_field_condition_id As Integer


        ' AlarmId = 110
        AlarmId = Session("AlarmId")
        'Response.Write(AlarmId)
        'Session("AlarmId") = AlarmId

        sel_node = AlarmView.SelectedValue

        If Len(sel_node) > 3 And sel_node.Substring(0, 3) = "CON" Then
            con_id = sel_node.Substring(3)
        Else
            Exit Sub
        End If

        'Dim sql As String

        'sql = "update v_alarm_definition_list "

        min_value = CInt(txt_min_value.Text)
        max_value = CInt(txt_max_value.Text)
        signal_id = " & ddl_signal_name.SelectedValue & "

        Dim include_min As String
        Dim include_max As String

        If ddl_include_min.SelectedValue = "LT" Then
            include_min = "N"
        Else
            include_min = "Y"
        End If

        If ddl_include_max.SelectedValue = "LT" Then
            include_max = "N"
        Else
            include_max = "Y"
        End If

        include_min = " & include_min & "
        include_max = " & include_max & "
        alarm_field_condition_id = CInt(con_id)

        'sql = sql & "include_max = '" & include_max & "' "

        'sql = sql & " where alarm_field_condition_id = " & con_id

        Try
            AlarmView.Nodes.Item(0).Text = CInt(txt_min_value.Text)
            AlarmView.Nodes.Item(1).Text = CInt(txt_max_value.Text)
            AlarmView.Nodes.Item(4).Text = ddl_signal_name.SelectedValue
            AlarmView.DataBind()



            ' Dim cmd As New SqlCommand(sql, Conn)

            ' Dim row_count = cmd.ExecuteNonQuery

            'cmd.Dispose()
        Catch ex As Exception

        End Try
        ReloadTree()
        DisconnectFromDb()

    End Sub



Thanks,

Sreekanth
Avatar of YZlat
YZlat
Flag of United States of America image

try
if AlarmView.Nodes > 1 then
AlarmView.Nodes.Item(1).Text = CInt(txt_max_value.Text)

end if
The error that you are getting is that there is no AlarmView.Nodes.Item(1) There is a AlarmView.Nodes.Item(0). Place a breakpoint at that line and see what if that is in AlarmView is what you think is there.
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial