Add node in ie treeview
Hi, i have a problem with adding nodes
Here is my code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim cn As New SqlConnection(cnString)
Dim cmd As New SqlCommand
Dim objReader As SqlDataReader
Dim strSQL As String
strSQL = "select ID, NAME from Table1"
With cmd
.Connection = cn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
cn.Open()
objReader = cmd.ExecuteReader
Dim n As New TreeNode
While (objReader.Read)
n.Text = objReader.Item("Name")
n.ImageUrl = "bs.gif"
n.Expandable = ExpandableValue.Always
n.ExpandedImageUrl = "bo.gif"
n.NodeData = objReader.Item("ID")
tvwHelp.Nodes.Add(n)
End While
End If
End Sub 'This is ok but I have a problem with next
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''
Private Sub tvwHelp_Expand(ByVal sender As Object, ByVal e As Microsoft.Web.UI.WebControls.TreeViewClickEventArg s) Handles tvwHelp.Expand
Dim cn As New SqlConnection(cnString)
Dim cmd As New SqlCommand
Dim objReader As SqlDataReader
Dim strSQL As String
Dim nE As TreeNode
Dim nodeRez As TreeNode
nE = sender.nodes(e.Node.ToString)
If nE.Nodes.Count = 0 Then
strSQL = " select ID,SINAME as NAME from TOC " _
& " where PARENTID =" & CInt(nE.NodeData.ToString) "
With cmd
.Connection = cn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
cn.Open()
objReader = cmd.ExecuteReader
While objReader.Read
nodeRez = New TreeNode
nodeRez.Text = objReader.Item("Name")
nodeRez.NodeData = objReader.Item("ID")
nodeRez.Expandable = ExpandableValue.Always
nE.Nodes.Add(nodeRez)
End While
Else
nE.Expanded = True
End If
End Sub
''''''''''''''''''''''''
tvwHelp_Expand works fine only for first time, but later when i want to expand any other child node i always get error:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.
How can i solve this problem?
Thanks very much
|