Articles in this section
Category / Section

How to select tree nodes in TreeView using code behind

1 min read

The TreeView component provides support to select tree nodes in both client-side and server-side. You can select the tree nodes using the SelectedNode property of TreeView component. The following code sample demonstrates how to select the tree nodes using code behind.

 

<ej:TreeView ID="TreeView1" runat="server" DataTextField="Text" DataIdField="Id" DataParentIdField="Parent" DataExpandedField="Expanded" DataHasChildField="HasChild"></ej:TreeView>

 

Select tree nodes using the SelectedNode property

protected void Page_Load(object sender, EventArgs e)
{
  List<LoadData> treeData = new List<LoadData>();
  treeData.Add(new LoadData { Id = 1, Parent = 0, Text = "Sendeos", Expanded = true });
  treeData.Add(new LoadData { Id = 2, Parent = 1, Text = "Masroig" });
  treeData.Add(new LoadData { Id = 3, Parent = 1, Text = "Brazal Foig" });
  treeData.Add(new LoadData { Id = 4, Parent = 1, Text = "Rec Nou" });
  TreeView1.Fields.DataSource = treeData;
  if (!IsPostBack)
     TreeView1.SelectedNode = 0;
  else
     TreeView1.SelectedNode = 1;
}

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied