Calling code-behind method on TreeNode click
I want to call a code-behind method when a TreeNode is clicked in my TreeView. I would imagine this isn't difficult to do, but I can't find a good example of how to do it.
I've looked at TreeNodeSelectAction, 开发者_JS百科but that appears to just be an enumeration, so I'm wondering how I can call my own code when a node is clicked.
Try add the SelectedNodeChanged event handler to the TreeView control. Then, you can select the method by the TreeNode name.
protected void MyTreeView_SelectedNodeChanged(object sender, EventArgs e)
{
TreeView treeView = sender as TreeView;
if (treeView != null)
{
TreeNode treeNode = treeView.SelectedNode;
}
}
Hope it helps
精彩评论