Crystalball

导航

ASP.NET中的treeview中如何获取该子节点的所有父节点

 1 protected string getParent(TreeNode currTreeNode)
 2     {
 3         string rv = "";
 4         if (currTreeNode.Parent != null)
 5         {
 6             rv = currTreeNode.Parent.Text;
 7             rv += getParent(currTreeNode.Parent);
 8         }
 9 
10         return rv;
11     }
12 
13     protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
14     {
15         Response.Write(getParent(TreeView1.SelectedNode));
16     }

问:
在展开一个带有子节点的父节点时,我点击了父节点前的"+"后,怎么得到父节点的ID?
______________________________________________________________________________________________
答1:
((TreeNode)TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex).Parent).Text;

posted on 2012-11-03 16:44  Crystalball  阅读(2842)  评论(0编辑  收藏  举报