title: Get TreeView Selected Node in JavaScript
body: <p>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.</p>
  <p>Is there any alternative to know the Node and whether the Node has any child or parent in JavaScript?</p>
  <p>Here is my example which i am using to create and populate TreeView:</p>
  <pre class="lang-js prettyprint-override"><code>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 = &quot;Provider=SQLOLEDB;Data Source = .; Initial Catalog = NorthWind; User ID = sa; Password = &quot;;
                          myCommand.CommandText = &quot;select EmployeeID, FirstName  + ' ' + LastName As Name from Employees Order by EmployeeID&quot;;
                          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[&quot;Name&quot;].ToString(), t_DR[&quot;EmployeeID&quot;].ToString());
                                  TreeView1.Nodes.Add(t_Node);
                              }
  
                          }
                          catch (Exception ex)
                          {
                              Response.Write(String.Format(&quot;There is an error{0}&quot;, ex));
                          }
                          finally
                          {
                              con.Close();
                          }
                      }
                  }
              }
          }
      }
  </code></pre>