1. Use
(1) Download address http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/ASP_DOT_NET_SERVERCONTROLS/WebControls/default.asp
(2) Do not show the problem of tree type First: Download the package automatically installed and manually installs two packages. To download the automatic installation package of about 650K. Second: TreeView requires client browser version of IE5.5 and above, it is best to request client upgrade to IE6.0
(3) About flashing the AutoPostBack property to true, SELECTEDEXCHANGE can be executed. However, this is very powerful. If you don't refresh, set the AutoPostBack property to False.
(4) Several properties and methods of commonly used properties and methods ~ INDEX get the position of the tree node in the tree node collection. ~ Nodes Get the tree node collection assigned to the tree view control. ~ Parent gets or sets the parent container for the control. ~ SelectedNode Gets or sets the tree node currently selected in the tree view control. ~ ExpandALL Expands all tree nodes. ~ Checked gets or sets a value to indicate if the tree node is selected. ~ Text Gets or sets the text displayed in the tree node tag. ~ Expand Expand the tree node. ~ CLEAR Clear Tree ~ Remove removes the current tree node from the tree view control.
(5) Commonly used operations: increase, delete, modify, cut
@ 加加 节: DIM TMPND3 AS New Microsoft.Web.ui.WebControls.treenode () Dim Ndsel As New Microsoft.Web.ui.WebControls.treenode () '' NDSEL is the currently selected node, the new node will be used as it child nodes NdSel = Treepaybasic.GetNodeFromIndex (Treepaybasic.SelectedNodeIndex) tmpNd3.Text = "Add node" '' to add the new node NdSel.Nodes.Add (tmpNd3) @ delete nodes in the tree: Dim tmpNd3 As new Microsoft.Web. UI.WebControls.TreeNode () Dim NdSel as New Microsoft.Web.UI.WebControls.TreeNode () '' NdSel for the currently selected node to be deleted, tmpNd3 as its parent node NdSel = Treepaybasic.GetNodeFromIndex (Treepaybasic.SelectedNodeIndex) If (Treepaybasic.SelectedNodeIndex <> "0") Then tmpNd3 = NdSel.Parent tmpNd3.Nodes.Remove (NdSel) Else Treepaybasic.Nodes.Clear () End If @ modify the node: Dim NdSel As New Microsoft.Web.UI.WebControls .Treenode () ndsel = treepaybasic.getnodeFromindex (TreePaybasic.selectedNodeIndex) ndsel.text = "aaa" @ cut and paste
Cut: DIM TMPND3 AS New Microsoft.Web.ui.WebControls.treenode () Dim Ndsel As New Microsoft.Web.ui.WebControls.treenode () 'NDSEL is the current selected to delete nodes, TMPND3 is its father node NdSel = Treepaybasic.GetNodeFromIndex (Treepaybasic.SelectedNodeIndex) '' will cut down the node stored session Session ( "node") = NdSel If (Treepaybasic.SelectedNodeIndex <> "0") Then tmpNd3 = NdSel.Parent tmpNd3.Nodes .Remove (ndsel) End IF Paste: DIM TMPND3 AS New Microsoft.Web.ui.WebControls.treenode () Dim Ndsel As New Microsoft.Web.ui.WebControls.treenode () '' NDSEL for the current Parent node to paste the node Ndsel = treepaybasic.getnodeFromindex (TreePayBasic.SelectedNodeIndex) TMPND3 = session ("node") NDSEL.NODES.ADD (TMPND3) 2. Design with recursive spanning tree and database design (1) Recursive description program calls itself Recursion. In the generation of the tree and the traversal of the map, there are many of the hands. The classic algorithm is n! (See the step by N), it is a recursive method. The advantages of the recursive algorithm are simple and expandable. But the disadvantage is also obvious: inefficient. Because recursive is that the program continues to call itself, it is relatively large for the resource consumption of the system. As the node increases, the execution efficiency will become very low. In order to solve the problem with the laminar tree during the generation process, it is also to make the tree's scalability better. The generation of the tree uses a recursive method. Once the code of the spanning tree is written, the source code can be generated, generating an unlimited level of the tree. The structure of the tree is completely determined by the data in the database. (2) Database design Create a database, design the tree graph information table Treetable, the property contains NodeID, ParentID, NodeName, Address, and other fields (used to represent nodes, parent node ID, node name, link address), others The property is determined according to the actual user needs and design. Node Nodename will display on the node of the tree control, the NodeID field saves the unique identification number of the node, and the ParentId represents the current node's parent ID number (for example, there are two nodes are the father and child relationship, the child's node's ParentID value is its parent node NodeID), the node number, the child, the parent, forms a "linked list", characterizes and records the hierarchy of the tree node. The table is specific to the following: (Simplified model, actually useful to be complex) Primary key attribute name type length can be explicitly attribute meaning is NodeId INT 6 No Node IDNODNAME CHAR 50 No Name Name Address CHAR 80 can be linked
Remarks: The link address is mainly used in: the environment used in the frame in the frame. The link can point to the address in other framepages or with different parameters.
(3) Program code ------------ Function Sub inittree (byref NDS AS Microsoft.Web.ui). WebControls.TreeNodeCollection, ByVal parentId as Integer) Dim dv as New DataView () Dim dvrow as DataRowView Dim tmpNode as Microsoft.Web.UI.WebControls.TreeNode '' intId numerical variable, whose role is to record the current record and the delivery ID , As the ParentID value DIM intid as integer dv.table = mySet.tables ("paybasic") 'ParentID is the intidID in the additem function, the role of the following statement is to find the child collection of the current node . DV.rowfilter = "ParentID = ''" "" If the current node has children, traverse all children and call the recursive function. For Each DVROW IN DV TMPNODE = New Microsoft.Web.ui.WebControls.treenode () 'assigns values for each attribute for the current node.
TmpNode.ID = DVROW ("NodeID") TmpNode.Text = DVROW ("Nodename") TmpNode.NaviGateURL = DVROW ("Address") intid = DVROW ("ParentID") 'adds a node nds.add (tmpnode)' 'Call recursive functions inittree (nds (nds.count - 1) .nodes, intid) Nextend Sub ---------------- Call recursive function ---------- -------- CreateReaderDataSet () infrasic.nodes, 999) ----------------- Generate data set ----------- -------- '' Generate Data Set Function Private Sub CreateReaderDataSet () 'Connects at runtime, and sets connection properties myconn = new system.data.oledb.oledbConnection ("provider = msdaora.1; data Source = ORACLE9; User ID = User; Password = ****; ") Sets SelectCommand command myadapter.selectcommand = new system.data.oledb.oledbcommand (" SELECT * from Treenode ", myconn) 'fill data set Myadapter.Fill (MySet, "Treenode") End Sub (1) First correct download and install IEWebControls (2) in vs.net