Effect:
Front-End Code:
1<%@ Master language="C #"autoeventwireup="true"Codebehind="Site1.master.cs"inherits="apmanage.site1"%>2 3<! DOCTYPE html>4 5"http://www.w3.org/1999/xhtml">6"Server">7<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>8<title></title>9<asp:contentplaceholder id="Head"runat="Server">Ten</asp:ContentPlaceHolder> One A<body> -<form id="Form1"runat="Server"> -<div> the<asp:treeview id="TreeView1"runat="Server"Onselectednodechanged ="treeview1_selectednodechanged"showlines="True"> -</asp:TreeView> -<asp:linkbutton id="LinkButton1"runat="Server"OnClick ="LinkButton1_Click"> Modify Nodes </asp:LinkButton> -<asp:contentplaceholder id="ContentPlaceHolder1"runat="Server"> + -</asp:ContentPlaceHolder> +</div> A</form> at</body> -View CodeBack-End Code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Data;4 usingSystem.Linq;5 usingsystem.web;6 usingSystem.Web.UI;7 usingSystem.Web.UI.WebControls;8 usingApmanage.app_code;9 usingSystem.Data.SqlClient;Ten One A namespaceApmanage - { - Public Partial classUpdateNodes:System.Web.UI.Page the { - protected voidPage_Load (Objectsender, EventArgs e) - { - This. Dropdownlist1.datasource = Sqlhelper.executetable ("SELECT * from tb_apcategory where parentid =", CommandType.Text); + This. Dropdownlist1.datavaluefield ="ID"; - This. Dropdownlist1.datatextfield ="CategoryName"; + This. Dropdownlist1.databind (); A at -List<category> inof =NewList<category>(); -SqlDataReader SDR = Sqlhelper.excutereader ("Select ID, CategoryName from tb_apcategory where parentid =", CommandType.Text); - while(SDR). Read ()) - { -SqlDataReader sdr_2 = Sqlhelper.excutereader ("Select ID, CategoryName from tb_apcategory where parentid ="+ sdr["ID"]. ToString () +"", CommandType.Text); in while(Sdr_2.read ()) - { toInof. ADD (NewCategory (sdr_2["ID"]. ToString (), sdr_2["CategoryName"]. ToString ())); + } - } the * This. Dropdownlist2.datasource =inof; $ This. Dropdownlist2.datavaluefield ="ID";Panax Notoginseng This. Dropdownlist2.datatextfield ="Name"; - This. Dropdownlist2.databind (); the + //This . Dropdownlist2.datasource = sqlhelper.executetable ("SELECT * from Tb_apcategory", CommandType.Text); A //This . Dropdownlist2.datavaluefield = ""; the //This . Dropdownlist2.datatextfield = ""; + //This . Dropdownlist2.databind (); - } $ $ Public classcategory - { - PublicCategorystringIdstringname) the { -Id =ID;WuyiName =name; the } - Wu Private stringID; - About Public stringId $ { - Get{returnID;} - Set{id =value;} - } A + Private stringname; the - Public stringName $ { the Get{returnname;} the Set{name =value;} the } the } - } in}
View CodeAsp.net-treeview Additions and deletions