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 in JavaScript?
Here is my example which i am using to create and populate TreeView:
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();
}
}
}
}
}
}