从另一个树形视图中获取父级和子级 [英] Get parent and child from another treeview

查看:89
本文介绍了从另一个树形视图中获取父级和子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,可以获取父节点和子节点,并且希望用户每次单击站点地图时由以下代码组成:

I have a function where I get the parent and the childnode and i want each time the user clicked on the sitemap wich is composed by the following code:

Label_fatdata.Text += "<a id="fatdata" style="removed:pointer; margin-removed0px; text-transform:uppercase; font-size:10px; font-weight:500;" önclick="\"click(TreeView1," snode="" mode="hold" />



我想用他从备份树中得到的节点(父+子)重绘主树.但是到目前为止,我遇到了很多问题...首先在if子句中,我需要使用备份树来验证元素"a".



i want that redraws the main tree with the node (parent + child) that he gets from the backup tree. But so far I am having a lot of problems...first in if clause i need to verify the element ''a'' with the backup tree.

void click(TreeView one, TreeView two)
        {
            if (one.SelectedNode.ValuePath == two.SelectedNode.ValuePath)
            {
                TreeNode parentdata = two.SelectedNode.Parent;
                TreeNodeCollection childdata = two.SelectedNode.ChildNodes;

                one.Nodes.Add(parentdata);
                one.Nodes[0].ChildNodes.Add(childdata[0]);
                one.Nodes.Clear();
                one.DataBind();
            }
        }

推荐答案

与其比较代码中的树,还不如:

1.将用户选择的值保存到会话或viewstate变量中

2.重绘树时,如果要重绘的节点的值=保存的变量,则添加If条件对父子节点执行所需的操作.您可以在TreeView.TreeNodeDataBound事件中执行此操作.简单.
Instead of comparing the trees like in your code, an easier approach would be to :

1. Save the value the user selects to a session or viewstate variable

2. When redrawing the tree, add If condition to do what you want with the parent child nodes if the value of the node being redrawn = the saved variable. You can do this in the TreeView.TreeNodeDataBound event. simple.


这篇关于从另一个树形视图中获取父级和子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆