I had the following problem with a treeview object:
As I have a quite big treeview-object, so that I store the built treeview-object in a session-variable (to win time when reloading a page). But when I attributed the stored object to the object placed in the page, the tree stays blanc. (first code)
To resolve the problem I put a placeholder in the page and then I attributed to the placeholder the treeview-object (second code). But now I do not know how to handle when someone clicks a noed-item.
So my problem can have two solutions:
1) get rid of the place-holder-solution and find how to attribute the stored treeview object to the treeview-object that is in the page. (=> I would prefer this solution)
2) or find out how to manage click events on the tree-object, when it is stored in a place-holder.
I would be very thankful if anybody could help me !!
first code (without placehoder, but it doesn't work when loading the page)
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load fill_TreeView() End Sub Public my_hierarchy As hierarchy Public my_dataset As DataSet Protected WithEvents TreeView1 As Microsoft.Web.UI.WebControls.TreeView Sub New() my_hierarchy = HttpContext.Current.Session("my_product_hierarchy") my_dataset = my_hierarchy.my_dataset_all_hierarchy_elements End Sub Public Function fill_TreeView() If HttpContext.Current.Session("my_TreeView") Is Nothing Then Treeview1 = New Microsoft.Web.UI.WebControls.TreeView Dim TreeNode As Microsoft.Web.UI.WebControls.TreeNode Dim my_DataView As DataView = New DataView my_DataView.Table = my_dataset.Tables(0) my_DataView.RowFilter = "parent_id = 0" For Each my_row As DataRowView In my_DataView TreeNode = New Microsoft.Web.UI.WebControls.TreeNode TreeNode.Text = my_row("short_name") TreeNode.ID = my_row("id") add_sub_MenuItems(TreeNode) Treeview1.Nodes.Add(TreeNode) Next HttpContext.Current.Session("my_TreeView") = Treeview1 Else Dim Treeview_tmp As Microsoft.Web.UI.WebControls.TreeView = HttpContext.Current.Session("my_TreeView") Treeview1 = Treeview_tmp End If treeview_inpage = TreeView1 'here is my problem : the treeview_inpage-object is well filled (tested it with treeview_inpage.Nodes.Count), but it keeps blanc at the output... End Function Private Function add_sub_MenuItems(ByRef parent_TreeNode As Microsoft.Web.UI.WebControls.TreeNode) Dim TreeNode As Microsoft.Web.UI.WebControls.TreeNode Dim my_DataView As DataView = New DataView my_DataView.Table = my_dataset.Tables(0) my_DataView.RowFilter = "parent_id = " & parent_TreeNode.ID For Each my_row As DataRowView In my_DataView TreeNode = New Microsoft.Web.UI.WebControls.TreeNode TreeNode.Text = my_row("short_name") TreeNode.ID = my_row("id") add_sub_MenuItems(TreeNode) parent_TreeNode.Nodes.Add(TreeNode) Next End Function
second code (with placehoder, but I do not know how to manage click-evnets...)
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load fill_TreeView() End Sub Public my_hierarchy As hierarchy Public my_dataset As DataSet Public Treeview1 As Microsoft.Web.UI.WebControls.TreeView Sub New() my_hierarchy = HttpContext.Current.Session("my_product_hierarchy") my_dataset = my_hierarchy.my_dataset_all_hierarchy_elements End Sub Public Function fill_TreeView() If HttpContext.Current.Session("my_TreeView") Is Nothing Then Treeview1 = New Microsoft.Web.UI.WebControls.TreeView Dim TreeNode As Microsoft.Web.UI.WebControls.TreeNode Dim my_DataView As DataView = New DataView my_DataView.Table = my_dataset.Tables(0) my_DataView.RowFilter = "parent_id = 0" For Each my_row As DataRowView In my_DataView TreeNode = New Microsoft.Web.UI.WebControls.TreeNode TreeNode.Text = my_row("short_name") TreeNode.ID = my_row("id") add_sub_MenuItems(TreeNode) Treeview1.Nodes.Add(TreeNode) Next HttpContext.Current.Session("my_TreeView") = Treeview1 Else Dim Treeview_tmp As Microsoft.Web.UI.WebControls.TreeView = HttpContext.Current.Session("my_TreeView") Treeview1 = Treeview_tmp End If PlaceHolder2.Controls.Add(Treeview1) ' when I use a placeholder like this it works, but I have a problem to deal with click-events... End Function Private Function add_sub_MenuItems(ByRef parent_TreeNode As Microsoft.Web.UI.WebControls.TreeNode) Dim TreeNode As Microsoft.Web.UI.WebControls.TreeNode Dim my_DataView As DataView = New DataView my_DataView.Table = my_dataset.Tables(0) my_DataView.RowFilter = "parent_id = " & parent_TreeNode.ID For Each my_row As DataRowView In my_DataView TreeNode = New Microsoft.Web.UI.WebControls.TreeNode TreeNode.Text = my_row("short_name") TreeNode.ID = my_row("id") add_sub_MenuItems(TreeNode) parent_TreeNode.Nodes.Add(TreeNode) Next End Function


Reply With Quote