We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

TreeView Node''s Treeview

on the Server Side, how would I get the Treeview ID of a node? I have the node, and I want to know what TreeView it belongs to.


4 Replies

VK Vishnu Kumar Syncfusion Team February 7, 2008 12:15 PM UTC

Hi Jan,

Thank you for your patience.

Issuehow would I get the Treeview ID of a node?

You can get the treeview id and node belogs to the treeview using the below code snippet :


protected void TreeView1_NodeSelected(object sender, TreeViewNodeEventArgs e)
{
if (e.Node.ID != "M1")
{
lblEvent.Text = "Selected Node ID:" + " " + e.Node.ID + "," + " " + "Selected Node Treeview ID Is :" + TreeView1.ID + "";
Label1.Text = "Selected Node Parent ID:" + " " + e.Node.ParentNode.ID + "";
}

}


Please refer the sample in the below link which illustrates the above:

http://websamples.syncfusion.com/samples/Tools.Web/6.1.0.34/71589/main.htm

Please try running the above sample and let me know if this helps.

Regards,
Vishnu.




KG Kathy Gray February 10, 2008 09:17 PM UTC

But, how do I know that e.node belongs to treeview1? What if there are more than one treeview on the page?



VK Vishnu Kumar Syncfusion Team February 13, 2008 01:06 PM UTC

Hi Jan,

Thank you for your patience.

Issue:how do I know that e.node belongs to treeview1? What if there are more than one treeview on the page?

You can get the treeview id and node belongs to the treeview by using Treeview node selected event. The following code snippet is used to achieve this behavior:


Treeview 1 :

protected void TreeView1_NodeSelected(object sender, TreeViewNodeEventArgs e)
{
if (e.Node.ID != "M1")
{
lblEvent.Text = "Selected Node ID:" + " " + e.Node.ID + "," + " " + "Selected Node Treeview ID Is :" + TreeView1.ID + "";
Label1.Text = "Selected Node Parent ID:" + " " + e.Node.ParentNode.ID + "";
}

}

Treeview 2 :
protected void TreeView2_NodeSelected(object sender, TreeViewNodeEventArgs e)
{
if (e.Node.ID != "M1")
{
lblEvent.Text = "Selected Node ID:" + " " + e.Node.ID + "," + " " + "Selected Node Treeview ID Is :" + TreeView2.ID + "";
Label1.Text = "Selected Node Parent ID:" + " " + e.Node.ParentNode.ID + "";
}
}



Please refer the modified sample in the below link which illustrates the above:

http://websamples.syncfusion.com/samples/Tools.Web/6.1.0.34/71589/main.htm

Please try running the above sample and let me know if this helps.

Regards,
Vishnu.




NR Nandakumar R Syncfusion Team February 15, 2008 01:33 PM UTC


Hi,

I regret for the inconvenience caused.

Normally in an event, the sender will be the control itself. So, you can get the instance of the control by triggering an event in the node and get the ID of that. Please try the below code and let me know if this helps.
    protected void TreeView1_NodeCheckChanged(object sender, Syncfusion.Web.UI.WebControls.Tools.TreeViewNodeEventArgs e)
{
Syncfusion.Web.UI.WebControls.Tools.TreeView _treeViewObj = sender as Syncfusion.Web.UI.WebControls.Tools.TreeView;
Response.Write(_treeViewObj.ID.ToString());
}

Thank you for your interest in Syncfusion Essential Studio.

Regards,
Nanda


Loader.
Live Chat Icon For mobile
Up arrow icon