Front Page:<%@ Page Language="C #"AutoEventWireup="true"codebehind="Default.aspx.cs"Inherits="Tree._default" %><!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml" ><Headrunat= "Server"> <title>Directory tree</title> <Scripttype= "Text/javascript"language= "JavaScript"src= "Mztreeview10.js"></Script> <Linkhref= "Css/global.css"type= "Text/css"rel= "stylesheet"/> <styletype= "Text/css">A.mztreeview{font-size:9pt;Padding-left:3px; } </style></Head><Body> <formID= "Form1"runat= "Server"> <Scripttype= "Text/javascript"language= "JavaScript"> <!--Window.tree= NewMztreeview ("Tree"); tree.icons[" Property"] = "Property.gif"; tree.icons["CSS"] = "Collection.gif"; tree.icons[" Book"] = "Book.gif"; tree.iconsexpand[" Book"] = "Bookopen.gif"; Tree.seticonpath ("/images/"); <%Loadtree ();%>Tree.seturl ("#"); Tree.settarget (""); document.write (Tree.tostring ()); - </Script> </form></Body></HTML>
background page:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.Sql;usingSystem.Data.SqlClient;usingtreedemo.dbutility;namespacetree{ Public Partial class_default:system.web.ui.page { Public Static stringstr; protected voidPage_Load (Objectsender, EventArgs e) { } Public voidLoadtree () {stringsql ="Select Id,isnull (pid,0) as pid,caption from Tree order by ID"; SqlDataReader Dr= Treewww.tydsyy.comDemo.DBUtility.SqlHelper.ExecuteReader (sqlhelper.connectionstring,commandtype.text, SQL,NULL); stringnode =""; while(Dr. Read ()) {node="\ r \ tree.nodes["+"\""+ dr["PID"]. ToString () +"_"+ dr["ID"]. ToString () +"\""+"] = "; Node= node +"\""+"Text:"+ dr["Caption"]. ToString () +";"+"\""; Response.Write (node); } if(!Dr. IsClosed) Dr. Close (); } }}
Simple and efficient ASP. NET directory tree source code