动态加载TreeNode -- ComponentArt TreeView

       ComponentArt是我所用过的第三方控件中比较优秀的一套。下面代码主要实现树节点的动态加载,比较简单,所以只贴代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProjectTree.ascx.cs" Inherits="Modules_Other_ProjectTree" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<ComponentArt:TreeView id="TreeView1" Height="350px" Width="100%" 
    DragAndDropEnabled
="false" 
    NodeEditingEnabled
="false"
    KeyboardEnabled
="true"
    CssClass
="TreeView" 
    NodeCssClass
="TreeNode" 
    SelectedNodeCssClass
="SelectedTreeNode" 
    HoverNodeCssClass
="HoverTreeNode"
    NodeEditCssClass
="NodeEdit"
    LineImageWidth
="19" 
    LineImageHeight
="20"
    DefaultImageWidth
="16" 
    DefaultImageHeight
="16"
    ItemSpacing
="0" 
    ImagesBaseUrl
="images/"
    NodeLabelPadding
="3"
    ShowLines
="true" 
    LineImagesFolderUrl
="images/lines/"
    EnableViewState
="true"
    runat
="server" LoadingFeedbackText="Loading " >
  
</ComponentArt:TreeView>

protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!Page.IsPostBack)
        
{
            TreeViewNode rootnode 
= new TreeViewNode();
            rootnode.Text 
= "项目";
            rootnode.Expanded 
= true;
            TreeView1.Nodes.Add(rootnode);

            ProjectDB pdb 
= new ProjectDB();
            IList
<Project.Model.Project> plist = pdb.ProjectList();
            
foreach (Project.Model.Project p in plist)
            
{
                 TreeViewNode pnode 
= new TreeViewNode();
                pnode.Text 
= p.PNO + " " + p.ProjectName;
                pnode.ID 
= p.Id.ToString();
                pnode.Value 
= "Project";
                pnode.ContentCallbackUrl 
= "Test.aspx?Pid=" + p.Id;
                rootnode.Nodes.Add(pnode);
            }
 
        }
      
    }


<%@ Page Language="C#" AutoEventWireUp="true" %>
<%@ import Namespace="System.Threading" %>
<%@ import Namespace="System.IO" %>
<%@ Import Namespace="Project.DAO" %>
<%@ Import Namespace="Project.Model" %>
<%@ import Namespace="ComponentArt.Web.UI" %>
<%@ Import Namespace="System.Collections.Generic" %>
<% Response.ContentType = "text/xml"%>
<script language="C#" runat="server" type="text/C#">
    
void Page_Load(Object sender, EventArgs e)
    
{
        ComponentArt.Web.UI.TreeView TreeView1 
= new ComponentArt.Web.UI.TreeView();

        ProjectDB pdb 
= new ProjectDB();
        
if (Request.QueryString["Pid"!= null && Request.QueryString["Pid"!= "")
        
{
            
int pid = int.Parse(Request.QueryString["Pid"]);

            IList
<ProjectStep> pslist = pdb.GetPstepByPid(pid, 0);
            foreach (ProjectStep ps 
in pslist)
            
{
                TreeViewNode node 
= new TreeViewNode();

                node.Text 
=  ps.StepName;
                node.ID 
= ps.Id.ToString();
                node.Value 
= "Step";
                
                TreeView1.Nodes.Add(node);
            }

        }


        Response.Write(TreeView1.GetXml());
    }

</script>

posted on 2007-01-04 14:00  Daniel Pang  阅读(4117)  评论(1编辑  收藏  举报

导航