Welcome Guest Search | Active Topics | Sign In | Register

TreeView Options
EPC DB
Posted: Wednesday, March 5, 2008 6:52:17 AM
Rank: Member
Groups: Member

Joined: 3/4/2008
Posts: 24
Hello,

I created a PO_TreeNode class inheriting TreeNode and I filled the first level of Treeview with that class.
I will like to dynamically fill the second level of the Treeview when the user clicks on the tree structure because I have an access to a database for each node and if I filled all the Treeview with the loading it is very long.

The function which filled the tree structure is as follows

Private Sub addChildNode(ByRef parentNode As PO_TreeNode, ByVal con As System.Data.OracleClient.OracleConnection)
Dim sql As String
Dim childSortOf As String
Dim cmd As System.Data.OracleClient.OracleCommand
Dim Rd As System.Data.OracleClient.OracleDataReader
Dim node As PO_TreeNode

If parentNode.sqlToGetChildren <> "" Then
Try
cmd = New System.Data.OracleClient.OracleCommand(parentNode.sqlToGetChildren, con)
Rd = cmd.ExecuteReader()
Catch ex As Exception
Me.ErrorMsg.Text = Me.ErrorMsg.Text & "Erreure de lecture des données Oracle : " & ex.Message & cmd.CommandText
Exit Sub
End Try
While Rd.Read()
node = New PO_TreeNode(Rd.GetValue(0), parentNode.Text, parentNode.parentName, parentNode.parentSortOf, con)
parentNode.ChildNodes.Add(node)
End While
End If
End Sub

The loading of the first level goes very well
But when I execute the function

Public Sub TreeView_ItemClick(ByVal sender As System.Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles TreeView.ItemClick
addChildNode(e.TreeNode, con)
End Sub

I get an Invalid Cast Exception

How to recover the PO_TreeNode class in the TreeView_ItemClick function

Cheers,

Patrice Bailly
Code: Visual Basic.NET
Code: Visual Basic.NET
eo_support
Posted: Wednesday, March 5, 2008 7:01:56 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi Patrice,

The TreeView knows how to recreated TreeNode based on previous populated data saved in the view state when the page posts back, however it has no knowledge about PO_TreeNode. So when the page posts back (at which point TreeView_ItemClick occurs), the TreeView will only have TreeNode objects, instead of PO_TreeNode object, that's why you are getting this error.

Instead of inheriting TreeNode, try to populate critcial information into TreeNode.Value and then carry out your logic based on that value. TreeNode.Value is saved across post backs.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.