代码
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); //递归调用,进行遍历
}
}
}
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); //递归调用,进行遍历
}
}
}