Implementation of tree functions in ASP. NET (1)

Source: Internet
Author: User
Tree charts are used to display data organized by tree structures. They are widely used, such as file systems (resource managers in Windows) in computers and composition structures of enterprises or companies. We know that in windows, tools such as VB, Pb, and Delphi provide a powerful tree-type control Treeview. Using the Treeview control, we can easily develop a tree chart. However, it is not so easy to implement tree embedding on the web page. net uses the Internet Explorer webcontrols provided by Microsoft to make the tree structure development on the web page as convenient as it is in Windows. The same functions are powerful and even more flexible.

This article describes how to use Internet Explorer webcontrols to develop a tree chart. Due to the complex structure of the tree chart, I often do not know how to use it. I have recently used ASP for my company. the specific example of the Application Manager compiled by. NET is described in detail in ASP. net, how to associate the use of Internet Explorer webcontrols with the database to display data in multiple layers, so as to conveniently add, modify, delete, and move data. I hope that through the elaboration of this instance, I will bring you a better result, communicate with colleagues, and make progress together.

Internet Explorer webcontrols is not in vs. Net's Standard Server Control, to download to Microsoft's site, is: http://msdn.microsoft.com/downloads/samples/internet/default.asp? Url =/downloads/samples/Internet/asp_dot_net_servercontrols/webcontrols/default. asp when you download and install it for the first time, right-click the Toolbox customize toolbox... → In. NET Framework components, select Micosoft. Web. UI. webcontrols. Treeview, And the Treeview control appears in the toolbox.

  I. Tree Creation

The specific method is to create a database and design the tree_info table of the tree chart, which contains the nodeid, parentid, nodename, adderss, and Icon fields. Other fields are determined based on the actual business, the node name nodename is displayed on the node of the tree control. The nodeid field stores the unique ID of the node. parentid indicates the parent node number of the current node. the ID number forms a "linked list ", the structure of the nodes on the tree is recorded. Design a web form and place the Treeview control on it.

 

Private sub createdataset () 'create a dataset
Dim myconn as new sqlconnection ()
Dim mycmd as new sqlcommand ("select nodeid, nodename, parentid, address, icon from tree_info", myconn)
Dim mydataadapter as new sqldataadapter ()
Myconn. connectionstring = Application ("connectstring ")
Mycmd. commandtext = ""
Mycmd. Connection = myconn
Mydataadapter. selectcommand = mycmd
Mydataadapter. Fill (DS, "Tree ")
End sub

The basic idea of building a tree is to recursively call the display subtree from the root node.

Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
Createdataset ()
Intitree (treeview1.nodes, 0)
End sub
Private sub intitree (byref NDS as treenodecollection, byval parentid as integer)
Dim DV as new dataview ()
Dim DRV as datarowview
Dim tmpnd as treenode
Dim intid as integer
DV. Table = Ds. Tables ("Tree ")
DV. rowfilter = "parentid = '" & parentid &"'"
For each DRV in DV
Tmpnd = new treenode ()
Strid = DRV ("node_id ")
Tmpnd. ID = Strid
Tmpnd. Text = DRV ("node_name ")
Tmpnd. imageurl = DRV ("icon"). tostring
NDS. Add (tmpnd)
Intitree (NDS. Count-1). nodes, intid)
Next
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.