APNSoft Controls []
TreeView > Defining the Structure

APNSoft TreeView uses XML for defining the structure since XML is the most convenient and widespread format for structured data. The XML Structure consists of elements (items and separators):

    <item title="About Us" />
    <item title="Products">
        <item title="Menu" />
        <item title="DataGrid" />
        <item title="TreeView" />
        <separator />
        <item title="Customization" />
    <item title="Contacts" />

The code above creates the following TreeView:

Structure elements:

TreeView element examples:

<item id="i1" title="Home" />
<item id="i1" title="Home" href="~/Default.aspx?ItemID=$ItemID$&amp;Rnd=$Rnd$" />
<item title="Google" href="http://www.google.com" target="_blank" />
<item title="JavaScript" ClientSideOnItemClick="alert('The $Title$ ($ItemID$) is clicked!');" />
<item title="Folder" icon="IconFolder.gif" iconOpen="IconFolderOpen.gif" />
<item title="TV Schedule" Template="~/Templates/Template.ascx" />
<separator width="120" />

Attention! Element names and attributes are case-sensitive. Be careful when you're typing in your data.

Applying the XML Structure or Data Source:

You can save the XML definition structure as a file and bind the TreeView by specifying the StructureFileURL property. APNSoft TreeView has support to use the Web.sitemap file as a standard TreeView structure.

<APNSoft:APNSoftTreeView id="myTreeView" runat="server"
    StructureFileURL = "~/Structures/TreeView.xml" />

You can also apply the XML Document with structure by using the DataSource property. If the TreeView loads structure from the database, you should set the DataSource property to specify a source of data and call the DataBind() method. To create an appropriate table in the SQL Server, use the following SQL command:

CREATE TABLE [dbo].[Items](
    [id] [nvarchar](20) NOT NULL,
    [pid] [nvarchar](20) NULL,
    [Type] [nvarchar](10) NOT NULL CONSTRAINT [DF_Items_Type] DEFAULT ('item'),
    [title] [nvarchar](250) NULL,
    [href] [nvarchar](250) NULL,
    [target] [nvarchar](100) NULL,
    [icon] [nvarchar](100) NULL,
    [iconOpen] [nvarchar](100) NULL,
    [iconWidth] [tinyint] NULL,
    [iconHeight] [tinyint] NULL,
    [AutoPostBackOnItemClick] [bit] 
        NOT NULL CONSTRAINT [DF_Items_AutoPostBackOnItemClick] DEFAULT ((0)),
    [ClientSideOnItemClick] [nvarchar](250) NULL,
    [selected] [bit] NOT NULL CONSTRAINT [DF_Items_selected] DEFAULT ((0)),
    [Checked] [bit] NOT NULL CONSTRAINT [DF_Items_Checked] DEFAULT ((0)),
    [opened] [bit] NOT NULL CONSTRAINT [DF_Items_opened] DEFAULT ((0)),
    [Template] [nvarchar](255) NULL

You can also build up TreeView at runtime. APNSoft TreeView provides an extremely rich and powerful server-side API allowing developer to add, remove or edit TreeView elements and element collections. You can programmatically control any item at runtime by using two classes TreeViewElement and TreeViewElementCollection.