Telerik TreeView | NodeExpand event provides invalid node value when using NodeTemplate

I am using Telerik version: 2009.3.1208.0

My task is to add an arrow to the node (on the right side of the node) so that people can left-click on it and get access to the context menu.

enter image description here

I was able to do this by creating a nodetemplate (subscribing to the interface) and then assigning my class to the NodeTemplate property (on the Init page)

Here is the code:

Imports System.Web.UI Imports System.Web.UI.WebControls Imports Telerik.Web.UI Public Class MyNodeTemplate Implements ITemplate Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn Dim newLabel As New Label() newLabel.CssClass = "nodeLabel" newLabel.Text = DirectCast(container, RadTreeNode).Text Dim arrowDiv As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV") arrowDiv.Attributes.Add("class", "nodeRightClickArrow") arrowDiv.Attributes.Add("onclick", "LeftClickContextMenuClick(event, this);") container.Controls.Add(newLabel) container.Controls.Add(arrowDiv) End Sub End Class 

Everything seems wonderful EXCEPT :

When expanding one of the nodes, the NodeExpand event sends an incorrect value for the node, which is expanding . For example, if I expand node 3, it gives me the value (e.Node.Value) for node 1. See the figure below for a more detailed explanation. As a result, the wrong child nodes are loaded. enter image description here

Questions:

1) Why does NodeExpand crash when adding a NodeTemplate?

2) Is there any way to achieve adding an arrow to a node so that people can left-click on it without overwriting NodeTemplate?

+4
source share
1 answer

I think you need to use the Node Click method, in Node click your code

 protected void treeView_NodeClick(object sender, RadTreeNodeEventArgs e) { int id; int.TryParse(e.Node.Value, out id); e.Node.Expanded = true // Expand the node manually, or IsExpanded, not remember } 

need to work. Aditionaly, you coldly expand Node manually. The Telerik documentation says that this event occurs when Node expands, so that means what happens when Node expands, and I think you need to expand node.

0
source

All Articles