|
asp.net 2.0中TREEVIEW中动态增加结点(1)
在ASP.net 2.0中,要动态从数据库中取出内容,动态增加结点,其实不难,比如以SQL SERVER 2000的PUBS数据库为例子,要以树型列表方式,取出作者,做为根结点,然后取出每位作者写过什么书,作为子结点,可以这样
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.SqlClient"%> <%@ Import Namespace="System.Configuration"%> <head runat="server"> <title>Dynamic Population of the TreeView Control</title> <script runat=server> void Node_Populate(object sender, System.Web.UI.WebControls.TreeNodeEventArgs e) { if(e.Node.ChildNodes.Count == 0) { switch( e.Node.Depth ) { case 0: FillAuthors(e.Node); break; case 1: FillTitlesForAuthors(e.Node); break; } } }
|