views:

1767

answers:

1

Hello Friends

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

A: 

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);
John Feminella
Hello Friend Thanks for your comment, let's say i am creating and populating my treeview as follows in the example below, please let me know how can i get the EmployeeID from the selected node in the TreeView. here follows the example.protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack){} BindTreeParent(); }
Everest
sorry for my previous comment without the example, here i donot know how to add code in this comment, hence i edited the above question to include the Code example for creating the TreeNode. now the problem is that i want the EmployeeID as selected by user from the TreeView using javascript. how to get that value. kindly please help me in this.waiting for replies.
Everest