zoukankan      html  css  js  c++  java
  • 用递归方法把资料绑定到TreeView控件,显示文档目录

    代码
    using System.Collections.Generic;
    using System.Reflection;
    using System.Data;
     
    partial class ViewFolder: System.Web.UI.Page
        {            
            
    protected void Page_Load(object sender, System.EventArgs e)
            {
                
    if (!Page.IsPostBack)
                {
                    GetNotes();
                }          
            }

            
    private void GetNotes()
            {            
                
    //根节点            
                TreeNode tn=new TreeNode("我的文档""0"this.ControlPath + "images/folder0.gif");
                
    int FolderControlID = DocumentController.GetTabId(this.PortalId, "ViewDocument");
                tn.NavigateUrl 
    = Globals.NavigateURL(FolderControlID, """FolderId=0");
                TreeFolder.Nodes.Add(tn);

                DataTable dt
    =null;
                
    try
                    {
                        dt 
    = DocumentController.GetListFolder(UserId);                    
                    }

                    
    catch (Exception exc)
                    {
                        
    //Module failed to load 
                        Exceptions.ProcessModuleLoadException(this, exc);
                    }            
                
    //增加子节点
                IntiTree(TreeFolder.Nodes , dt, 0);       

                TreeNode dustbin 
    = new TreeNode("垃圾箱""-1");
                dustbin.ImageUrl 
    = this.ControlPath + "images/Dustbin.gif";
                TreeFolder.Nodes.Add(dustbin);
            }
            
    //递归增加子节点
            private void IntiTree(TreeNodeCollection Nds,DataTable dt, int parentId)
            {
                DataView dv
    =new DataView();                      
                TreeNode tmpNd;            
    //创建临时节点

                dv.Table 
    = dt;
                dv.RowFilter 
    = "ParentFolderId=" + parentId;        //筛选数据
                int FolderControlID = DocumentController.GetTabId(this.PortalId, "ViewDocument");

                
    foreach(DataRowView drv in dv)
                {
                    tmpNd
    =new TreeNode();
                    
    int FolderId=Convert.ToInt32(drv["FolderId"]);            //当前节点的ID号
                    tmpNd.Value=FolderId.ToString();
                    tmpNd.Text
    =drv["FolderName"].ToString();

                    
    string navUrl = "javascript:navurl('" + "http://" + Request.Url.Host + ResolveUrl("../Document/callIndex.aspx?FolderId=");
                    tmpNd.NavigateUrl 
    = navUrl + drv["FolderId"].ToString() + "')"

                    tmpNd.ImageUrl 
    = "images/folder1.gif";   
                    tmpNd.Expanded 
    = false;                                  //节点是否展开   
                    
    //tmpNd.Target="main";                                //节点重定向的方向                 
                    Nds[Nds.Count-1].ChildNodes.Add(tmpNd);               //将临时节点添加到TreeView菜单中
                    IntiTree(Nds[Nds.Count-1].ChildNodes,dt,FolderId);        //递归调用,进行遍历
                }

             }
    }
  • 相关阅读:
    get和post区别
    linux查看是否被入侵
    (转)MSSQL 各个发行版本版本号以及Compact 版本号
    (转)玩转-数据库行列转换
    (转)理解SQL SERVER中的分区表
    (转)使用CruiseControl+SVN+ANT实现持续集成之三
    (转)使用CruiseControl+SVN+ANT实现持续集成之二
    (转)使用SVN+CruiseControl+ANT实现持续集成之一
    (转)持续化集成工具CruiseControl.NET
    (转)DockPanel 右键增加关闭,除此之外全部关闭的功能
  • 原文地址:https://www.cnblogs.com/fredx/p/1622459.html
Copyright © 2011-2022 走看看