How to expand specific Tree View Node programmatically in ASP.NET

How to expand specific Tree View Node programmatically in ASP.NET ?

ASP.NET TreeView control is a server side control for displaying data in a hierarchical formats. TreeView  contains multiple nodes and sub nodes. Many times we bind a large number of data with tree view for users to navigate data, pages, or displaying any other details information. If there are many nodes and sub nodes in TreeView, sometime  it’s quite difficult for a user  to find out a specific nodes. On that kind of situation we can give a functionally to user so that they can search for the tree node and can be expand automatically if its found.
image
In this case you can use FindNode() method to find a particular node and then use Expand() method to expand that particular node.  FindNode() take node name as argument and return TreeNode if it’s found. You may even use ExpandAll() method to expand all the subsequent child nodes.
Expanding Specific Node using Expand() Method
[sourcecode language="csharp"]
protected void buttonSearch_Click(object sender, EventArgs e)
{
aspTreeView.CollapseAll();
TreeNode searchNode = aspTreeView.FindNode(textSearch.Text);
if (searchNode != null)
searchNode.Expand();
}
[/sourcecode]
image

Expanding all subsequent Child Nodes using ExpandAll() Method
[sourcecode language="csharp"]
protected void buttonSearch_Click(object sender, EventArgs e)
{
aspTreeView.CollapseAll();
TreeNode searchNode = aspTreeView.FindNode(textSearch.Text);
if (searchNode != null)
searchNode.ExpandAll();
}
[/sourcecode]
image


Sagar S Bhanushali

Comments

Popular posts from this blog

All Google Hacking Keyword - New Updated

Download Windows 8 Activators