在JavaScript中获取TreeView选定的节点 [英] Get TreeView Selected Node in JavaScript

查看:86
本文介绍了在JavaScript中获取TreeView选定的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,可以使用javascript简单地了解TreeView中的选定节点.假设在父子关系中有n个节点,那么我想在javascript中获取所选节点的值,以便我可以操纵和处理javascript中所选的值,而不是进行整页的回发以获取所选的值用户在ASP.Net中选择的树节点.

I am looking to find a way to just simply know the selected node in TreeView using javascript. suppose there are n number of nodes in the Parent Child Relationship, then what i want to get value of the selected node in javascript so that i can manipulate and work on the values selected in javascript rather than do a full page postback to get the selected Tree node as selected by user in ASP.Net.

是否有其他方法可以知道节点以及该节点是否有任何子代或父代(如果在JavaScript中是否存在)

is there any alternative to know the Node and whether the Node has any child or parent if any in javascript or not

这是我用来创建和填充TreeView的示例抱歉,没有提供示例的最后一条评论,这是完整的示例

here is my example which i am using to create and populate TreeView sorry for the last comment without the example, here is the full example


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TreeNode t_Node;
            using (OleDbConnection con = new OleDbConnection())
            {
                using (DataSet t_DS = new DataSet())
                {
                    using (OleDbCommand myCommand = new OleDbCommand())
                    {
                        OleDbDataAdapter t_DA;
                        con.ConnectionString = "Provider=SQLOLEDB;Data Source = .; Initial Catalog = NorthWind; User ID = sa; Password = ";
                        myCommand.CommandText = "select EmployeeID, FirstName  + ' ' + LastName As Name from Employees Order by EmployeeID";
                        myCommand.Connection = con;
                        try
                        {
                            con.Open();
                            t_DA = new OleDbDataAdapter(myCommand);
                            t_DA.Fill(t_DS);
                            foreach (DataRow t_DR in t_DS.Tables[0].Rows)
                            {
                                t_Node = new TreeNode(t_DR["Name"].ToString(), t_DR["EmployeeID"].ToString());
                                TreeView1.Nodes.Add(t_Node);
                            }

                        }
                        catch (Exception ex)
                        {
                            Response.Write(String.Format("There is an error{0}", ex));
                        }
                        finally
                        {
                            con.Close();
                        }
                    }
                }
            }
        }
    }

寻找有利的答复

谢谢

推荐答案

您将拥有一个名为{TreeView name} _Data的对象.所有多汁的部分都在那里.要获取选定的节点,您需要selectedNodeID属性.例如,如果您有一个名为Products的TreeView,请尝试以下操作:

You'll have an object called {TreeView name}_Data. All the juicy parts are in there. To get the selected node, you want the selectedNodeID property. For example, if you have a TreeView called Products, then try this:

var selectedItem = Products_Data.selectedNodeID.value;
var selectedNode = Document.getElementById(selectedItem);

这篇关于在JavaScript中获取TreeView选定的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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