开发者

Extend .NET TreeView CheckBox

I have a .NET TreeView control with checkboxes on the leaves. I want to be able to get the value of the node when a checkbox is selected. Basically, this is a tree of 开发者_StackOverflowemail contacts and when the user selects a checkbox I want to pull the node value (email address) and place that in a text box. The second part is no problem, I'll just call a JS function to append the email to the text box.

So, the issue is how to extract the node's value from the checkbox with JS. Unless someone has an alternate method, I was thinking about extending the TreeView to not include a normal checkbox but rather one that can store a value. Note: I have an existing control called CheckBoxValue that will do exactly this. Fundamentally, my question is how can I extend the TreeView to include this? I believe this would be in the CreateChildControls method but would love some help.

Any ideas?

Thanks, Ryan


If the value you are trying to store is a string then you could use TreeNode.Value to store it. Here's an example you could refer to.

 <asp:TreeView ID="TreeView1" runat="server"  onclick=" __doPostBack('','');"
        ontreenodecheckchanged="TreeView1_TreeNodeCheckChanged">
    </asp:TreeView>

and to load the tree

        if (!IsPostBack)
        {
            TreeNode node = new TreeNode("RootNode");
            TreeView1.Nodes.Add(node);

            TreeNode childNode = new TreeNode("ChildNode");
            childNode.ShowCheckBox = true;
            childNode.Value = "foo@bar.com";
            node.ChildNodes.Add(childNode);
        }

and the check CheckChanged event handler

    protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
    {
        TextBox1.Text = e.Node.Value;
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜