Javascript – Get TreeView Selected Node in JavaScript

asp.netjavascripttreeview

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.

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

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();
                        }
                    }
                }
            }
        }
    }

Looking for favorable replies

Thanks

Best Answer

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);