Martijn
Martijn

Reputation: 24789

C#: How to use a custom TreeView object?

If you create a custom TreeView and TreeNode like this:

public class CustomTreeNode : TreeNode
{
    private int customInt;

    public int CustomInt
    {
        get
        {
            return customInt;
        }
        set
        {
            customInt= value;
        }
    }

}

public class CustomTreeView : TreeView
{
    protected override TreeNode CreateNode()
    {
        return new CustomTreeNode();
    }
}

How do I use this in code? How in my aspx page can I use this TreeView?

Upvotes: 0

Views: 1679

Answers (1)

Slavo
Slavo

Reputation: 15463

You have to either put this code in App_Code or build it in an assembly. Then in the ASPX, you need a @Register directive, which will include the namespace with your new control. In case you put it in App_Code the assembly would be App_Code. Then once it is included, you can create it on the page with the defined tag prefix. Here's what I mean:

<%@ Page Language="C#"%>
<%@ Register Assembly="MyBuiltAssembly" Namespace="CustomTreeViewNamespace" TagPrefix="test" %>

...

<test:CustomTreeView ID="CustomTreeView1" runat="server">

Upvotes: 1

Related Questions