开发者

Calling code-behind method on TreeNode click

开发者 https://www.devze.com 2023-03-02 14:00 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消