ASP.NET to generate microsoft.web.ui.webControls.treeView

xiaoxiao2021-04-09  517

Support the oil paper umbrella, alone in a long, long and lonely rain;

Changing the database,

Create View Miaoccasselect FID AS ID, SNAME AS Name, PID AS PIDFROM FSORTUNIONSELECT FID AS ID, SNAME AS NAME, SID AS PIDFROM TSORTUNISELECT SID AS ID, SNAME AS NAME, FID AS PIDFROM SSORT

Private void addtree (string id, treenode pnode) {sqlConnection myconnection = new sqlconnection (system.configuration.configurationSettings.appsettings ["db"]);

DataSet ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset (myConnection, System.Data.CommandType.Text, "select * from miaoCC where PID = '" id "'"); DataView dv = new DataView (ds.Tables [0]); Foreach (DataRowView Row In DV) {Treenode Node = New Treenode (); if (PNode == Null) {node.text = row ["name"]. TOSTRING (); TreeView1.nodes [0] .Nodes.add (node); node.imageurl = "images / home.gif"; node.expandedimageurl = "images / btn2.gif"; node.expanded = false; addtree (row ["iD"]. Tostring () ,} else {node.text = row ["name"]. Tostring (); node.id = row ["id"]. Tostring (); pnode.nodes.add (node); node.expanded = False; node.imageurl = "images / home.gif"; node.expandedimageurl = "images / btn2.gif"; addtree (row ["id"]. Tostring (), node);}}

The three tables are combined with UNION, that is, the classic iterative algorithm is realized.

That is, it is generated in the query, three columns must be;

ID Content ParentID

AddTree ("0", (Treenode) NULL;

, Then call;

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

New Post(0)