ASP.NET 2005 TreeView Unlimited Category Non-Recurrent Ultimate Solution

xiaoxiao2021-03-30  207

This question did two days when I wrote HRM, haha! Starting with Google for a long time is a bunch of garbage, all using algorithms, and later find www.asp.net to find some points revelation.

It's not easy to say nonsense.

First, the table structure is named TEST

Write a stored procedure gettreeView

Don't say this, I will use it.

For speed cache DATATABLE

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 A

Public Sub Populatenodes (Byval Nodes As Treenodecollection, Optional Byval INTPARENTID AS INT32 = 0)

DIM DT As New DataTable ()

Dt = clswebforms.gettreeetable ()

DIM strexpression as string

strexpression = "[ParentID] =" & intParentID

Dim FoundRows () AS DATAROW

FoundRows = dt.select (strexpression)

DIM I as integer

For i = 0 tofactrows.getupperbound (0)

Dim tn 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

Establish WebForm Add TreeView

Protected Sub Page_load (Byval e as system.eventargs) Handles Me.Load

IF not page.ispostback then

Populatenodes (TreeView1.nodes, 0)

End ifend sub

Protected Sub TreeView1_treenodepopulate (Byval e as system.web.ui.webcontrols.treenodeeventargs) Handles TreeView1.treenodePopulation

Populatenodes (E.Node.childNodes, E.Node.Value)

End Sub

As for speed, I have not tested it. If you are interested in helping meat.

The external words (suddenly found himself old, 26 years old, have written a few years of programs, have been using VB various versions, and MASM (MS Macro Surface Language) Established in VB 6.0 era 2000 to establish VB programming Personal Homepage Programming Waste) by Shadow

转载请注明原文地址:https://www.9cbs.com/read-130682.html

New Post(0)