TREENODESRC Attribute | TreeNodeSrc Property

Sets or retrieves a value that indicates the URL of an XML file, System.String, or XML data island containing TreeNode elements.

Syntax

ASP <tagPrefix:ELEMENT TREENODESRC = sTreeNodeSrc ... >
Script [ sTreeNodeSrc = ] object.TreeNodeSrc

Possible Values

tagPrefix Required. The element prefix associated with the WebControls namespace (Microsoft.Web.UI.WebControls). A TagPrefix is defined using the directive.
sTreeNodeSrc A value that indicates the URL of an XML file, System.String, or XML data island containing TreeNode elements.

The property is read/write. The property has no default value.

Remarks

You can encapsulate and reuse trees or pieces of trees in an XML data island. The XML file must contain only TreeNode elements wrapped in opening and closing TREENODES tags.

When TreeNodeSrc is a property of the TreeView element, the content of the XML data island renders in place of any content of TreeView. However, the TreeNodeType elements within the TreeView are not replaced.

When TreeNodeSrc is a property of the TreeNode element, the XML data island renders as child nodes of the TreeNode element.

The XML data island inherits the namespace of the databound element. The XML file must not contain any namespaces.

The XML data island must be syntactically well-formed XML.

You can transform the XML file specified by this property by setting the TreeNodeXsltSrc property to the URL of an Extensible Stylesheet Language (XSL) style sheet.

Examples

This is an example of an XML data island.

<TREENODES>
    <TREENODE TEXT="Document-1" IMAGEURL="folder.gif"
        EXPANDEDIMAGEURL="folderopen.gif"/>
    <TREENODE TEXT="Folder-1" EXPANDED="true"
        IMAGEURL="folder.gif" EXPANDEDIMAGEURL="folderopen.gif">
        <TREENODE TEXT="Document-2" />
        <TREENODE TEXT="Document-3" />
    </TREENODE>
    <TREENODE TEXT="Document-4" IMAGEURL="folder.gif"/>
</TREENODES>

Using the previous example of an XML data island and saving it to a file called treenodes.xml, the following example demonstrates how to set the TreeNodeSrc attribute of the TreeView element to the file.

<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Register TagPrefix="mytree" 
Namespace="Microsoft.Web.UI.WebControls" 
Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    
<HTML>

<BODY>

<FORM ID="debug" runat="server" >
    <mytree:TREEVIEW runat="server" id="oTree"
        DEFAULTSTYLE="font: 12pt verdana" SYSTEMIMAGESPATH="treeimages"
        CHILDTYPE="folder" TREENODESRC="treenodes.xml" />
</FORM>

</BODY>
</HTML>

The TreeNodeSrc attribute of the TreeView element can also be set to a System.String containing the TreeNode elements as shown in the following example.

<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Register TagPrefix="mytree" 
Namespace="Microsoft.Web.UI.WebControls" 
Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    
<HTML>

<BODY>

<FORM ID="debug" runat="server" >
    <mytree:TREEVIEW ID="tvw1" runat="server"
        DEFAULTSTYLE="font: 12pt verdana" SYSTEMIMAGESPATH="treeimages"
        CHILDTYPE="folder"
        TREENODESRC="<TREENODES>
            <TREENODE TEXT='Document-1' IMAGEURL='images/folder.gif'
                EXPANDEDIMAGEURL='images/folderopen.gif'/>
            <TREENODE TEXT='Folder-1' EXPANDED='true'
                IMAGEURL='images/folder.gif'
                EXPANDEDIMAGEURL='images/folderopen.gif'>
                <TREENODE TEXT='Document-2' />
                <TREENODE TEXT='Document-3' />
            </TREENODE>
            <TREENODE TEXT='Document-4' IMAGEURL='images/folder.gif'/>
        </TREENODES>" />
</FORM>

</BODY>
</HTML>

Applies To

TREENODE, TREEVIEW

See Also

Internet Explorer WebControls, About the TreeView WebControl