Treeview unlimited Classification Non-recursive Ultimate Solution

Source: Internet
Author: User
Table Structure: Table Name Test

 

 

Write a stored procedure gettreeview

I don't need to talk about this. I will use it below.

 

Cache datatable for speed

Public Function gettreetable () as datatable

Dim dT as new datatable ()

Dt = httpcontext. Current. cache ("Treeview ")

If dt is nothing then

Dim conn as new sqlconnection

Dim clsconndatabase as new connectiondatabase

Conn = clsconndatabase. conndatabase

 

Dim command as new sqlcommand

Command. Connection = Conn

Command. commandtext = "gettreeview"

Command. commandtype = commandtype. storedprocedure

Command. executenonquery ()

 

Dim da as new sqldataadapter (command)

Dt = new datatable ()

Da. Fill (DT)

Httpcontext. Current. cache. insert ("Treeview", DT)

End if

Return dt

End Function

 

Here is the main

Public sub populatenodes (byval nodes as treenodecollection, optional byval intparentid as int32 = 0)

Dim dT as new datatable ()

Dt = clswebforms. gettreetable ()

Dim strexpression as string

Strexpression = "[parentid] =" & intparentid

Dim foundrows () as datarow

Foundrows = DT. Select (strexpression)

 

Dim I as integer

For I = 0 to foundrows. getupperbound (0)

Dim tn as new treenode ()

Tn. Text = foundrows (I). Item ("tablename"). tostring ()

Tn. value = foundrows (I). Item ("ID"). tostring ()

Dim DR () as datarow

Dr = DT. Select ("[parentid] =" & tn. value)

If dr. getupperbound (0)>-1 then

Tn. populateondemand = true

End if

Nodes. Add (TN)

Next

End sub

 

Create a webform and put it in the Treeview

Protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. Load

If not page. ispostback then

Populatenodes (treeview1.nodes, 0)

End if

End sub

 

Protected sub treeviewinclutreenodepopulate (byval sender as object, byval e as system. Web. UI. webcontrols. treenodeeventargs) handles treeview1.treenodepopulate

Populatenodes (E. node. childnodes, E. node. value)

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.