TreeView Class
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Displays hierarchical data, such as a table of contents, in a tree structure.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)


[ControlValuePropertyAttribute("SelectedValue")]
public class TreeView : HierarchicalDataBoundControl, IPostBackEventHandler, 
	IPostBackDataHandler, ICallbackEventHandler
[ControlValuePropertyAttribute("SelectedValue")]
public ref class TreeView : HierarchicalDataBoundControl, IPostBackEventHandler, 
	IPostBackDataHandler, ICallbackEventHandler
[<ControlValuePropertyAttribute("SelectedValue")>]
type TreeView = 
    class
        inherit HierarchicalDataBoundControl
        interface IPostBackEventHandler
        interface IPostBackDataHandler
        interface ICallbackEventHandler
    end
<ControlValuePropertyAttribute("SelectedValue")>
Public Class TreeView
	Inherits HierarchicalDataBoundControl
	Implements IPostBackEventHandler, IPostBackDataHandler, ICallbackEventHandler
NameDescription
System_CAPS_pubmethod TreeView

Initializes a new instance of the TreeView class.

NameDescription
System_CAPS_pubproperty

Gets or sets the access key that allows you to quickly navigate to the Web server control.(Inherited from WebControl.)

System_CAPS_protproperty

Gets the browser-specific adapter for the control.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the application-relative virtual directory of the Page or UserControl object that contains this control.(Inherited from Control.)

System_CAPS_pubproperty

Gets the collection of arbitrary attributes (for rendering only) that do not correspond to properties on the control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets a value indicating whether the TreeView control automatically generates tree node bindings.

System_CAPS_pubproperty

Gets or sets the background color of the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

This API supports the product infrastructure and is not intended to be used directly from your code. Gets the control that contains this control's data binding.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the border color of the Web control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets the border style of the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets the border width of the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets a collection of TreeNode objects that represent the nodes in the TreeView control that display a selected check box.

System_CAPS_protproperty

Gets a value that indicates whether the server control's child controls have been created.(Inherited from Control.)

System_CAPS_pubproperty

Gets the control ID for HTML markup that is generated by ASP.NET.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the algorithm that is used to generate the value of the property.(Inherited from Control.)

System_CAPS_protproperty

Gets a character value representing the separator character used in the property.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the ToolTip for the image that is displayed for the collapsible node indicator.

System_CAPS_pubproperty

Gets or sets the URL to a custom image for the collapsible node indicator.

System_CAPS_protproperty

Gets the HttpContext object associated with the server control for the current Web request.(Inherited from Control.)

System_CAPS_pubproperty

Gets a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy.(Inherited from Control.)

System_CAPS_pubproperty

Gets the style of the Web server control. This property is used primarily by control developers.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets a value indicating whether a Style object has been created for the property. This property is primarily used by control developers.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets a collection of TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to.

System_CAPS_pubproperty

Gets a reference to the naming container if the naming container implements IDataItemContainer.(Inherited from Control.)

System_CAPS_pubproperty

Gets a reference to the naming container if the naming container implements IDataKeysControl.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the object from which the data-bound control retrieves its list of data items.(Inherited from BaseDataBoundControl.)

System_CAPS_pubproperty

Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protproperty

Gets a value indicating whether a control is being used on a design surface.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets a value indicating whether the TreeView control renders client-side script to handle expanding and collapsing events.

System_CAPS_pubproperty

Gets or sets a value indicating whether the Web server control is enabled.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets a value indicating whether themes apply to this control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.(Inherited from Control.)

System_CAPS_protproperty

Gets a list of event handler delegates for the control. This property is read-only.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the number of levels that are expanded when a TreeView control is displayed for the first time.

System_CAPS_pubproperty

Gets or sets the ToolTip for the image that is displayed for the expandable node indicator.

System_CAPS_pubproperty

Gets or sets the URL to a custom image for the expandable node indicator.

System_CAPS_pubproperty

Gets the font properties associated with the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets the foreground color (typically the color of the text) of the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets a value indicating whether the control has attributes set.(Inherited from WebControl.)

System_CAPS_protproperty

Gets a value indicating whether the current server control's child controls have any saved view-state settings.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the height of the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of a node when the mouse pointer is positioned over it.

System_CAPS_pubproperty

Gets or sets the programmatic identifier assigned to the server control.(Inherited from Control.)

System_CAPS_protproperty

This API supports the product infrastructure and is not intended to be used directly from your code. Gets the character used to separate control identifiers.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the group of images to use for the TreeView control.

System_CAPS_protproperty

Gets a value indicating whether the data-bound control has been initialized.(Inherited from BaseDataBoundControl.)

System_CAPS_protproperty

Gets a value indicating whether the property is set.(Inherited from BaseDataBoundControl.)

System_CAPS_protproperty

Gets a value indicating whether controls contained within this control have control state.(Inherited from Control.)

System_CAPS_protproperty

Gets a value that indicates whether data binding is automatic.(Inherited from BaseDataBoundControl.)

System_CAPS_protproperty

Gets a value indicating whether the control is enabled.(Inherited from WebControl.)

System_CAPS_protproperty

Gets a value that indicates whether the server control is saving changes to its view state.(Inherited from Control.)

System_CAPS_protproperty

When implemented in a derived class, gets a value that indicates whether the control is using model binders.(Inherited from BaseDataBoundControl.)

System_CAPS_protproperty

Gets a value indicating whether view state is enabled for this control.(Inherited from Control.)

System_CAPS_pubproperty

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of leaf nodes.

System_CAPS_pubproperty

Gets a collection of Style objects that represent the node styles at the individual levels of the tree.

System_CAPS_pubproperty

Gets or sets the path to a folder that contains the line images that are used to connect child nodes to parent nodes.

System_CAPS_protproperty

Gets a value indicating whether the control participates in loading its view state by instead of index. (Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the maximum number of tree levels to bind to the TreeView control.

System_CAPS_pubproperty

Gets a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same property value.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the indentation amount (in pixels) for the child nodes of the TreeView control.

System_CAPS_pubproperty

Gets a collection of TreeNode objects that represents the root nodes in the TreeView control.

System_CAPS_pubproperty

Gets a reference to the TreeNodeStyle object that allows you to set the default appearance of the nodes in the TreeView control.

System_CAPS_pubproperty

Gets or sets a value indicating whether text wraps in a node when the node runs out of space.

System_CAPS_pubproperty

Gets or sets the URL to a custom image for the non-expandable node indicator.

System_CAPS_pubproperty

Gets a reference to the Page instance that contains the server control.(Inherited from Control.)

System_CAPS_pubproperty

Gets a reference to the server control's parent control in the page control hierarchy.(Inherited from Control.)

System_CAPS_pubproperty

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of parent nodes in the TreeView control.

System_CAPS_pubproperty

Gets or sets the character that is used to delimit the node values that are specified by the property.

System_CAPS_pubproperty

Gets or sets a value indicating whether node data is populated on demand from the client.

System_CAPS_pubproperty

Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.(Inherited from Control.)

System_CAPS_protproperty

Gets or sets a value indicating whether the DataBind method should be called. (Inherited from BaseDataBoundControl.)

System_CAPS_pubproperty

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of the root node in the TreeView control.

System_CAPS_pubproperty

Gets a TreeNode object that represents the selected node in the TreeView control.

System_CAPS_pubproperty

Gets the TreeNodeStyle object that controls the appearance of the selected node in the TreeView control.

System_CAPS_pubproperty

Gets the value of the selected node.

System_CAPS_pubproperty

Gets or sets a value indicating which node types will display a check box in the TreeView control.

System_CAPS_pubproperty

Gets or sets a value indicating whether expansion node indicators are displayed.

System_CAPS_pubproperty

Gets or sets a value indicating whether lines connecting child nodes to parent nodes are displayed.

System_CAPS_pubproperty

Gets information about the container that hosts the current control when rendered on a design surface.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the skin to apply to the control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets a value that is used to render alternate text for screen readers to skip the content for the control.

System_CAPS_pubproperty

Gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets a value that indicates whether the control should set the disabled attribute of the rendered HTML element to "disabled" when the control's property is false.(Inherited from BaseDataBoundControl.)

System_CAPS_pubproperty

Gets or sets the tab index of the Web server control.(Inherited from WebControl.)

System_CAPS_protproperty

Gets the System.Web.UIHtmlTextWriterTag value for the TreeView control.(Overrides .)

System_CAPS_protproperty

Gets the name of the control tag. This property is used primarily by control developers.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets or sets the target window or frame in which to display the Web page content that is associated with a node.

System_CAPS_pubproperty

Gets or sets a reference to the template that contains this control. (Inherited from Control.)

System_CAPS_pubproperty

Gets the virtual directory of the Page or UserControl that contains the current server control.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the text displayed when the mouse pointer hovers over the Web server control.(Inherited from WebControl.)

System_CAPS_pubproperty

Gets the unique, hierarchically qualified identifier for the server control.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets a value that indicates whether the control checks client input from the browser for potentially dangerous values.(Inherited from Control.)

System_CAPS_protproperty

Gets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page.(Inherited from Control.)

System_CAPS_protproperty

Gets a value that indicates whether the StateBag object is case-insensitive.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets the view-state mode of this control.(Inherited from Control.)

System_CAPS_pubproperty

Gets or sets a value indicating whether the control is rendered as UI on the page. (Overrides .)

System_CAPS_pubproperty

Gets or sets the width of the Web server control.(Inherited from WebControl.)

NameDescription
System_CAPS_protmethod AddAttributesToRender

Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter control.(Overrides WebControlAddAttributesToRender.)

System_CAPS_protmethod AddedControl

Called after a child control is added to the collection of the Control object.(Inherited from Control.)

System_CAPS_protmethod AddParsedSubObject

Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object.(Inherited from Control.)

System_CAPS_pubmethod ApplyStyle

Copies any nonblank elements of the specified style to the Web control, overwriting any existing style elements of the control. This method is primarily used by control developers.(Inherited from WebControl.)

System_CAPS_pubmethod ApplyStyleSheetSkin

Applies the style properties defined in the page style sheet to the control.(Inherited from Control.)

System_CAPS_protmethod BeginRenderTracing

Begins design-time tracing of rendering data.(Inherited from Control.)

System_CAPS_protmethod BuildProfileTree

This API supports the product infrastructure and is not intended to be used directly from your code. Gathers information about the server control and delivers it to the property to be displayed when tracing is enabled for the page.(Inherited from Control.)

System_CAPS_protmethod ClearCachedClientID

This API supports the product infrastructure and is not intended to be used directly from your code. Sets the cached value to null.(Inherited from Control.)

System_CAPS_protmethod ClearChildControlState

Deletes the control-state information for the server control's child controls. (Inherited from Control.)

System_CAPS_protmethod ClearChildState

Deletes the view-state and control-state information for all the server control's child controls.(Inherited from Control.)

System_CAPS_protmethod ClearChildViewState

Deletes the view-state information for all the server control's child controls.(Inherited from Control.)

System_CAPS_protmethod ClearEffectiveClientIDMode

This API supports the product infrastructure and is not intended to be used directly from your code. Sets the property of the current control instance and of any child controls to Inherit.(Inherited from Control.)

System_CAPS_pubmethod CollapseAll

Closes every node in the tree.

System_CAPS_protmethod ConfirmInitState

Sets the initialized state of the data-bound control.(Inherited from BaseDataBoundControl.)

System_CAPS_pubmethod CopyBaseAttributes

Copies the properties not encapsulated by the object from the specified Web server control to the Web server control that this method is called from. This method is used primarily by control developers.(Inherited from WebControl.)

System_CAPS_protmethod CreateChildControls

Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.(Inherited from Control.)

System_CAPS_protmethod CreateControlCollection

Creates a collection to store child controls.(Overrides ControlCreateControlCollection.)

System_CAPS_protmethod CreateControlStyle

Creates the style object that is used internally by the WebControl class to implement all style related properties. This method is used primarily by control developers.(Inherited from WebControl.)

System_CAPS_protmethod CreateNode

This API supports the product infrastructure and is not intended to be used directly from your code. Returns a new instance of the TreeNode class. The CreateNode is a helper method.

System_CAPS_pubmethod DataBind

Calls the DataBind method of the base class. (Overrides BaseDataBoundControlDataBind.)

System_CAPS_protmethod DataBind

Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event. (Inherited from Control.)

System_CAPS_protmethod DataBindChildren

Binds a data source to the server control's child controls.(Inherited from Control.)

System_CAPS_pubmethod Dispose

Enables a server control to perform final clean up before it is released from memory.(Inherited from Control.)

System_CAPS_protmethod EndRenderTracing

Ends design-time tracing of rendering data.(Inherited from Control.)

System_CAPS_protmethod EnsureChildControls

Determines whether the server control contains child controls. If it does not, it creates child controls.(Inherited from Control.)

System_CAPS_protmethod EnsureDataBound

Calls the DataBind method if the property is set and the data-bound control is marked to require binding.(Inherited from BaseDataBoundControl.)

System_CAPS_protmethod EnsureID

Creates an identifier for controls that do not have an identifier assigned.(Inherited from Control.)

System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethod ExpandAll

Opens every node in the tree.

System_CAPS_protmethod Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethod FindControl

Searches the current naming container for a server control with the specified id parameter.(Inherited from Control.)

System_CAPS_protmethod FindControl

This API supports the product infrastructure and is not intended to be used directly from your code. Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method.(Inherited from Control.)

System_CAPS_pubmethod FindNode

Retrieves the TreeNode object in the TreeView control at the specified value path.

System_CAPS_pubmethod Focus

Sets input focus to a control.(Inherited from Control.)

System_CAPS_protmethod GetCallbackResult

Returns the result of a callback event that targets a control.

System_CAPS_protmethod GetData

Retrieves a HierarchicalDataSourceView object that the data-bound control uses to perform data operations.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod GetDataSource

Retrieves the IHierarchicalDataSource that the data-bound control is associated with, if any.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod GetDesignModeState

This API supports the product infrastructure and is not intended to be used directly from your code. Gets design-time data for a control.(Inherited from Control.)

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetRouteUrl

Gets the URL that corresponds to a set of route parameters.(Inherited from Control.)

System_CAPS_pubmethod GetRouteUrl

Gets the URL that corresponds to a set of route parameters.(Inherited from Control.)

System_CAPS_pubmethod GetRouteUrl

Gets the URL that corresponds to a set of route parameters and a route name.(Inherited from Control.)

System_CAPS_pubmethod GetRouteUrl

Gets the URL that corresponds to a set of route parameters and a route name.(Inherited from Control.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod GetUniqueIDRelativeTo

Returns the prefixed portion of the property of the specified control.(Inherited from Control.)

System_CAPS_pubmethod HasControls

Determines if the server control contains any child controls.(Inherited from Control.)

System_CAPS_protmethod HasEvents

Returns a value indicating whether events are registered for the control or any child controls.(Inherited from Control.)

System_CAPS_protmethod IsLiteralContent

This API supports the product infrastructure and is not intended to be used directly from your code. Determines if the server control holds only literal content.(Inherited from Control.)

System_CAPS_protmethod LoadControlState

Restores control-state information from a previous page request that was saved by the SaveControlState method.(Inherited from Control.)

System_CAPS_protmethod LoadPostData

Processes postback data for the TreeView control.

System_CAPS_protmethod LoadViewState

This API supports the product infrastructure and is not intended to be used directly from your code. Loads the previously saved view state of the TreeView control.(Overrides WebControlLoadViewState.)

System_CAPS_protmethod MapPathSecure

Retrieves the physical path that a virtual path, either absolute or relative, maps to.(Inherited from Control.)

System_CAPS_protmethod MarkAsDataBound

Sets the state of the control in view state as successfully bound to data.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethod MergeStyle

Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. This method is used primarily by control developers.(Inherited from WebControl.)

System_CAPS_protmethod OnBubbleEvent

Determines whether the event for the server control is passed up the page's UI server control hierarchy.(Inherited from Control.)

System_CAPS_protmethod OnDataBinding

Raises the DataBinding event.(Inherited from Control.)

System_CAPS_protmethod OnDataBound

Raises the DataBound event.(Inherited from BaseDataBoundControl.)

System_CAPS_protmethod OnDataPropertyChanged

Called when one of the base data source identification properties is changed, to re-bind the data-bound control to its data.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod OnDataSourceChanged

Called when the IHierarchicalDataSource instance that the data-bound control works with raises the DataSourceChanged event.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod OnInit

Raises the Init event.(Overrides BaseDataBoundControlOnInit.)

System_CAPS_protmethod OnLoad

Handles the Load event.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod OnPagePreLoad

Sets the initialized state of the data-bound control before the control is loaded.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod OnPreRender
System_CAPS_protmethod OnSelectedNodeChanged

Raises the SelectedNodeChanged event of the TreeView control.

System_CAPS_protmethod OnTreeNodeCheckChanged

Raises the TreeNodeCheckChanged event of the TreeView control.

System_CAPS_protmethod OnTreeNodeCollapsed

Raises the TreeNodeCollapsed event of the TreeView control.

System_CAPS_protmethod OnTreeNodeDataBound

Raises the TreeNodeDataBound event of the TreeView control.

System_CAPS_protmethod OnTreeNodeExpanded

Raises the TreeNodeExpanded event of the TreeView control.

System_CAPS_protmethod OnTreeNodePopulate

Raises the TreeNodePopulate event of the TreeView control.

System_CAPS_protmethod OnUnload

Raises the Unload event.(Inherited from Control.)

System_CAPS_protmethod OpenFile

Gets a Stream used to read a file.(Inherited from Control.)

System_CAPS_protmethod PerformDataBinding

This API supports the product infrastructure and is not intended to be used directly from your code. Creates all the nodes based on the data source.(Overrides HierarchicalDataBoundControlPerformDataBinding.)

System_CAPS_protmethod PerformSelect

Retrieves data from the associated data source.(Inherited from HierarchicalDataBoundControl.)

System_CAPS_protmethod RaiseBubbleEvent

Assigns any sources of the event and its information to the control's parent.(Inherited from Control.)

System_CAPS_protmethod RaiseCallbackEvent

This API supports the product infrastructure and is not intended to be used directly from your code. Raises the callback event using the specified arguments.

System_CAPS_protmethod RaisePostBackEvent

Enables the TreeView control to process an event that is raised when a form is posted to the server. The RaisePostBackEvent method is a helper method for the ICallbackEventHandlerRaiseCallbackEvent method.

System_CAPS_protmethod RaisePostDataChangedEvent

This API supports the product infrastructure and is not intended to be used directly from your code. Signals the TreeView control to notify the ASP.NET application that the state of the control has changed.

System_CAPS_protmethod RemovedControl

Called after a child control is removed from the collection of the Control object.(Inherited from Control.)

System_CAPS_protmethod Render

Renders the control to the specified HTML writer.(Inherited from WebControl.)

System_CAPS_pubmethod RenderBeginTag

Renders the HTML opening tag of the control to the specified writer. (Overrides WebControlRenderBeginTag.)

System_CAPS_protmethod RenderChildren

Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client.(Inherited from Control.)

System_CAPS_protmethod RenderContents

Renders the nodes in the TreeView control.(Overrides WebControlRenderContents.)

System_CAPS_pubmethod RenderControl

Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.(Inherited from Control.)

System_CAPS_protmethod RenderControl

Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.(Inherited from Control.)

System_CAPS_pubmethod RenderEndTag

Renders the HTML closing tag of the control to the specified writer.(Overrides WebControlRenderEndTag.)

System_CAPS_protmethod ResolveAdapter

Gets the control adapter responsible for rendering the specified control.(Inherited from Control.)

System_CAPS_pubmethod ResolveClientUrl

Gets a URL that can be used by the browser.(Inherited from Control.)

System_CAPS_pubmethod ResolveUrl

Converts a URL into one that is usable on the requesting client.(Inherited from Control.)

System_CAPS_protmethod SaveControlState

Saves any server control state changes that have occurred since the time the page was posted back to the server.(Inherited from Control.)

System_CAPS_protmethod SaveViewState

This API supports the product infrastructure and is not intended to be used directly from your code. Saves the state of the TreeView control.(Overrides WebControlSaveViewState.)

System_CAPS_protmethod SetDesignModeState

Sets design-time data for a control.(Inherited from Control.)

System_CAPS_protmethod SetNodeDataBound

Allows a derived class to set whether the specified TreeNode control is data-bound.

System_CAPS_protmethod SetNodeDataItem

Allows a derived class to set the data item for the specified TreeNode control.

System_CAPS_protmethod SetNodeDataPath

Allows a derived class to set the data path for the specified TreeNode control.

System_CAPS_pubmethod SetRenderMethodDelegate

This API supports the product infrastructure and is not intended to be used directly from your code. Assigns an event handler delegate to render the server control and its content into its parent control.(Inherited from Control.)

System_CAPS_pubmethod SetTraceData

Sets trace data for design-time tracing of rendering data, using the trace data key and the trace data value.(Inherited from Control.)

System_CAPS_pubmethod SetTraceData

Sets trace data for design-time tracing of rendering data, using the traced object, the trace data key, and the trace data value.(Inherited from Control.)

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_protmethod TrackViewState

This API supports the product infrastructure and is not intended to be used directly from your code. Tracks view-state changes to the TreeView control so that they can be stored in the System.Web.UIStateBag object for the control. This System.Web.UIStateBag is accessible through the property.(Overrides WebControlTrackViewState.)

System_CAPS_protmethod ValidateDataSource

Verifies that the object a data-bound control binds to is one it can work with.(Inherited from HierarchicalDataBoundControl.)

NameDescription
System_CAPS_pubevent DataBinding

Occurs when the server control binds to a data source.(Inherited from Control.)

System_CAPS_pubevent DataBound

Occurs after the server control binds to a data source.(Inherited from BaseDataBoundControl.)

System_CAPS_pubevent Disposed

Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.(Inherited from Control.)

System_CAPS_pubevent Init

Occurs when the server control is initialized, which is the first step in its lifecycle.(Inherited from Control.)

System_CAPS_pubevent Load

Occurs when the server control is loaded into the Page object.(Inherited from Control.)

System_CAPS_pubevent PreRender

Occurs after the Control object is loaded but prior to rendering.(Inherited from Control.)

System_CAPS_pubevent SelectedNodeChanged

Occurs when a node is selected in the TreeView control.

System_CAPS_pubevent TreeNodeCheckChanged

Occurs when a check box in the TreeView control changes state between posts to the server.

System_CAPS_pubevent TreeNodeCollapsed

Occurs when a node is collapsed in the TreeView control.

System_CAPS_pubevent TreeNodeDataBound

Occurs when a data item is bound to a node in the TreeView control.

System_CAPS_pubevent TreeNodeExpanded

Occurs when a node is expanded in the TreeView control.

System_CAPS_pubevent TreeNodePopulate

Occurs when a node with its property set to true is expanded in the TreeView control.

System_CAPS_pubevent Unload

Occurs when the server control is unloaded from memory.(Inherited from Control.)

NameDescription
System_CAPS_pubinterface System_CAPS_privmethod IAttributeAccessorGetAttribute

This API supports the product infrastructure and is not intended to be used directly from your code. Gets an attribute of the Web control with the specified name.(Inherited from WebControl.)

System_CAPS_pubinterface System_CAPS_privmethod IAttributeAccessorSetAttribute

Sets an attribute of the Web control to the specified name and value.(Inherited from WebControl.)

System_CAPS_pubinterface System_CAPS_privmethod ICallbackEventHandlerGetCallbackResult

This API supports the product infrastructure and is not intended to be used directly from your code. Returns the result of a callback event that targets a control.

System_CAPS_pubinterface System_CAPS_privmethod ICallbackEventHandlerRaiseCallbackEvent

This API supports the product infrastructure and is not intended to be used directly from your code. Raises the callback event using the specified arguments.

System_CAPS_pubinterface System_CAPS_privmethod IControlDesignerAccessorGetDesignModeState

For a description of this member, see IControlDesignerAccessorGetDesignModeState.(Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privmethod IControlDesignerAccessorSetDesignModeState

For a description of this member, see IControlDesignerAccessorSetDesignModeState. (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privmethod IControlDesignerAccessorSetOwnerControl

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IControlDesignerAccessorSetOwnerControl. (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privmethod IParserAccessorAddParsedSubObject

For a description of this member, see IParserAccessorAddParsedSubObject. (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privmethod IPostBackDataHandlerLoadPostData

This API supports the product infrastructure and is not intended to be used directly from your code. Processes postback data for the TreeView control.

System_CAPS_pubinterface System_CAPS_privmethod IPostBackDataHandlerRaisePostDataChangedEvent

This API supports the product infrastructure and is not intended to be used directly from your code. Signals the TreeView control to notify the ASP.NET application that the state of the control has changed.

System_CAPS_pubinterface System_CAPS_privmethod IPostBackEventHandlerRaisePostBackEvent

This API supports the product infrastructure and is not intended to be used directly from your code. Enables the TreeView control to process an event that is raised when a form is posted to the server.

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see . (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see . (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see . (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see . (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see . (Inherited from Control.)

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see . (Inherited from Control.)

NameDescription
System_CAPS_pubmethod EnablePersistedSelection

Obsolete. Enables selection to be persisted in data controls that support selection and paging.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod FindDataSourceControl

Returns the data source that is associated with the data control for the specified control.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod FindFieldTemplate

Returns the field template for the specified column in the specified control's naming container.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod FindMetaTable

Returns the metatable object for the containing data control.(Defined by DynamicDataExtensions.)

In this topic:

  • Introduction

  • Nodes

  • Static Data

  • Binding to Data

  • Dynamic Node Population

  • Customizing the User Interface

  • Events

  • Scrolling

  • Accessibility

  • Declarative Syntax

The TreeView control is used to display hierarchical data, such as a table of contents or file directory, in a tree structure and supports the following features:

  • Data binding that allows the nodes of the control to be bound to XML, tabular, or relational data.

  • Site navigation through integration with the SiteMapDataSource control.

  • Node text that can be displayed as either plain text or hyperlinks.

  • Programmatic access to the TreeView object model to create trees, populate nodes, set properties, and so on dynamically.

  • Client-side node population (on supported browsers).

  • The ability to display a check box next to each node.

  • Customizable appearance through themes, user-defined images, and styles.

    System_CAPS_noteNote

    The TreeView control is designed to be used inside an UpdatePanel control only when is set to true. UpdatePanel controls are used to update selected regions of a page instead of updating the whole page with a postback. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.

The TreeView control is made up of nodes. Each entry in the tree is called a node and is represented by a TreeNode object. Node types are defined as follows:

  • A node that contains other nodes is called a parent node.

  • The node that is contained by another node is called a child node.

  • A node that has no children is called a leaf node.

  • The node that is not contained by any other node but is the ancestor to all the other nodes is the root node.

A node can be both a parent and a child, but root, parent, and leaf nodes are mutually exclusive. Several visual and behavioral properties of nodes are determined by whether a node is a root, child, or leaf node.

Although a typical tree structure has only one root node, the TreeView control allows you to add multiple root nodes to your tree structure. This is useful when you want to display item listings without displaying a single root node, as in a list of product categories.

Each node has a property and a property. The value of the property is displayed in the TreeView, while the property is used to store any additional data about the node, such as data that is passed to the postback event that is associated with the node.

A node can be in one of two modes: selection mode and navigation mode. By default, a node is in selection mode. To put a node into navigation mode, set the property for the node to a value other than an empty string (""). To put a node into selection mode, set the property for the node to an empty string ("").

System_CAPS_noteNote

Some Internet browsers have a limitation that can affect the performance of the TreeView control. For example, Microsoft Internet Explorer 6.0 has a URL character limit of 2067 characters that it posts. If the number of characters in a URL of a node is larger than that number, expanding that node will fail and no exception is thrown.

The simplest data model of the TreeView control is static data. To display static data using declarative syntax, first nest opening and closing <Nodes> tags between the opening and closing tags of the TreeView control. Next, create the tree structure by nesting <asp:TreeNode> elements between the opening and closing <Nodes> tags. Each <asp:TreeNode> element represents a node in the tree and maps to a TreeNode object. You can set the properties of each node by setting the attributes of its <asp:TreeNode> element. To create child nodes, nest additional <asp:TreeNode> elements between the opening and closing <asp:TreeNode> tags of the parent node.

The TreeView control can also be bound to data. You can use either of two methods to bind the TreeView control to the appropriate data source type:

  • The TreeView control can use any data source control that implements the IHierarchicalDataSource interface, such as an XmlDataSource control or a SiteMapDataSource control. To bind to a data source control, set the property of the TreeView control to the value of the data source control. The TreeView control automatically binds to the specified data source control. This is the preferred method to bind to data.

  • The TreeView control can also be bound to an XmlDocument object or a DataSet object with relations. To bind to one of these data sources, set the property of the TreeView control to the data source, and then call the DataBind method.

When binding to a data source where each data item contains multiple properties (such as an XML element with several attributes), a node displays the value that is returned by the ToString method of the data item, by default. In the case of an XML element, the node displays the element name, which shows the underlying structure of the tree but is not very useful otherwise. You can bind a node to a specific data item property by specifying tree node bindings using the collection. The collection contains TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to. You can specify the criteria for binding and the data item property to display in the node. For more information on tree node bindings, see TreeNodeBinding.

System_CAPS_security Security Note

A malicious user can create a callback request and get data for the nodes of the TreeView control that the page developer is not displaying. Therefore, security of the data must be implemented by the data source. Do not use the property to hide data.

Sometimes, it is not practical to statically define the tree structure because the data source returns too much data or because the data to display depends on information that you get at run time. Because of this, the TreeView control supports dynamic node population. When the property for a node is set to true, that node gets populated at run time when the node is expanded. To populate a node dynamically, you must define an event-handling method that contains the logic to populate a node for the TreeNodePopulate event.

Browsers that support callback scripts can also take advantage of client-side node population. (This includes Internet Explorer 5.5 and later and some other browsers.) Client-side node population enables the TreeView control to populate a node using client script when users expand the node, without requiring a round trip to the server. For more information on client-side node population, see .

There are many ways to customize the appearance of the TreeView control. First, you can specify a different style (such as font size and color) for each of the node types.

If you use cascading style sheets (CSS) to customize the appearance of the control, use either inline styles or a separate CSS file, but not both. Using both inline styles and a separate CSS file could cause unexpected results. For more information on using style sheets with controls, see ASP.NET Web Server Controls and CSS Styles.

The following table lists the available node styles.

Node style property

Description

The style settings for a node when the mouse pointer is positioned over it.

The style settings for the leaf nodes.

The default style settings for a node.

The style settings for the parent nodes.

The style settings for the root node.

The style settings for a selected node.

You can also control the style of nodes at specific depths within the tree by using the collection. The first style in the collection corresponds to the style of the nodes at the first level in the tree. The second style in the collection corresponds to the style of the nodes at the second level in the tree, and so on. This is most often used to generate table of contents–style navigation menus where nodes at a certain depth should have the same appearance, regardless of whether they have child nodes.

System_CAPS_noteNote

If a style is defined for a certain depth level using the collection, that style overrides any root, parent, or leaf node style settings for the nodes at that depth.

Another way to alter the appearance of the control is to customize the images that are displayed in the TreeView control. You can specify your own custom set of images for the different parts of the control by setting the properties shown in the following table.

Image property

Description

The URL to an image displayed for the collapsible node indicator. This image is usually a minus sign (-).

The URL to an image displayed for the expandable node indicator. This image is usually a plus sign (+).

The URL to the folder containing the line images used to connect parent nodes to child nodes. The property must also be set to true for this property to have an effect.

The URL to an image displayed for the non-expandable node indicator.

System_CAPS_noteNote

You do not need to customize every image property. If an image property is not explicitly set, the built-in default image is used.

The TreeView control also allows you to display a check box next to a node. When the property is set to a value other than TreeNodeTypes.None, check boxes are displayed next to the specified node types.

System_CAPS_noteNote

The property can be set to a bitwise combination of the TreeNodeTypes enumeration member values.

Each time the page is posted to the server, the collection is automatically populated with the selected nodes. When check boxes are displayed, you can use the TreeNodeCheckChanged event to run a custom routine whenever the state of a check box changes between posts to the server.

The TreeView control provides several events that you can program against. This allows you to run a custom routine whenever an event occurs. The following table lists the events that are supported by the TreeView control.

Event

Description

TreeNodeCheckChanged

Occurs when the check boxes of the TreeView control change state between posts to the server.

SelectedNodeChanged

Occurs when a node is selected in the TreeView control.

TreeNodeExpanded

Occurs when a node is expanded in the TreeView control.

TreeNodeCollapsed

Occurs when a node is collapsed in the TreeView control.

TreeNodePopulate

Occurs when a node with its property set to true is expanded in the TreeView control.

TreeNodeDataBound

Occurs when a data item is bound to a node in the TreeView control.

The TreeView control does not have built-in scrolling. To add scrolling, place the TreeView control in a Panel control and add scrollbars to the Panel control. For more information, see Panel Web Server Control Overview.

The markup rendered by default for this control might not conform to accessibility standards. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

<asp:TreeView
    AccessKey="string"
    AutoGenerateDataBindings="True|False"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CollapseImageToolTip="string"
    CollapseImageUrl="uri"
    CssClass="string"
    DataSource="string"
    DataSourceID="string"
    EnableClientScript="True|False"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    ExpandDepth="string|FullyExpand|0|1|2|3|4|5|6|7|8|9|10|11|12|13|
        14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30"
    ExpandImageToolTip="string"
    ExpandImageUrl="uri"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
       Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    ImageSet="Custom|XPFileExplorer|Msdn|WindowsHelp|Simple|Simple2|
        BulletedList|BulletedList2|BulletedList3|BulletedList4|
        Arrows|News|Contacts|Inbox|Events|Faq"
    LineImagesFolder="string"
    MaxDataBindDepth="integer"
    NodeIndent="integer"
    NodeWrap="True|False"
    NoExpandImageUrl="uri"
    OnDataBinding="DataBinding event handler"
    OnDataBound="DataBound event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnSelectedNodeChanged="SelectedNodeChanged event handler"
    OnTreeNodeCheckChanged="TreeNodeCheckChanged event handler"
    OnTreeNodeCollapsed="TreeNodeCollapsed event handler"
    OnTreeNodeDataBound="TreeNodeDataBound event handler"
    OnTreeNodeExpanded="TreeNodeExpanded event handler"
    OnTreeNodePopulate="TreeNodePopulate event handler"
    OnUnload="Unload event handler"
    PathSeparator="string"
    PopulateNodesFromClient="True|False"
    runat="server"
    ShowCheckBoxes="None|Root|Parent|Leaf|All"
    ShowExpandCollapse="True|False"
    ShowLines="True|False"
    SkinID="string"
    SkipLinkText="string"
    Style="string"
    TabIndex="integer"
    Target="string"
    ToolTip="string"
    Visible="True|False"
    Width="size"
>
        <DataBindings>
                <asp:TreeNodeBinding
                    DataMember="string"
                    Depth="integer"
                    FormatString="string"
                    ImageToolTip="string"
                    ImageToolTipField="string"
                    ImageUrl="uri"
                    ImageUrlField="string"
                    NavigateUrl="uri"
                    NavigateUrlField="string"
                    PopulateOnDemand="True|False"
                    SelectAction="Select|Expand|SelectExpand|None"
                    ShowCheckBox="string"
                    Target="string"
                    TargetField="string"
                    Text="string"
                    TextField="string"
                    ToolTip="string"
                    ToolTipField="string"
                    Value="string"
                    ValueField="string"
                />
        </DataBindings>
        <HoverNodeStyle />
        <LeafNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <LevelStyles>
                <asp:TreeNodeStyle
                    BackColor="color name|#dddddd"
                    BorderColor="color name|#dddddd"
                    BorderStyle="NotSet|None|Dotted|Dashed|Solid|
                        Double|Groove|Ridge|Inset|Outset"
                    BorderWidth="size"
                    ChildNodesPadding="size"
                    CssClass="string"
                    Font-Bold="True|False"
                    Font-Italic="True|False"
                    Font-Names="string"
                    Font-Overline="True|False"
                    Font-Size="string|Smaller|Larger|XX-Small|
                        X-Small|Small|Medium|Large|X-Large|XX-Large"
                    Font-Strikeout="True|False"
                    Font-Underline="True|False"
                    ForeColor="color name|#dddddd"
                    Height="size"
                    HorizontalPadding="size"
                    ImageUrl="uri"
                    NodeSpacing="size"
                    OnDisposed="Disposed event handler"
                    VerticalPadding="size"
                    Width="size"
                />
        </LevelStyles>
        <Nodes>
                <asp:TreeNode
                    Checked="True|False"
                    Expanded="string"
                    ImageToolTip="string"
                    ImageUrl="uri"
                    NavigateUrl="uri"
                    PopulateOnDemand="True|False"
                    SelectAction="Select|Expand|SelectExpand|None"
                    Selected="True|False"
                    ShowCheckBox="string"
                    Target="string"
                    Text="string"
                    ToolTip="string"
                    Value="string"
>
                </asp:TreeNode>
        </Nodes>
        <NodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <ParentNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <RootNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <SelectedNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
</asp:TreeView>

This section contains seven code examples:

  • The first code example demonstrates how to set up the frames for the second code example.

  • The second code example demonstrates how to use declarative syntax to display static data in the TreeView control.

  • The third code example demonstrates how to bind the TreeView control to an XML data source.

  • The fourth code example provides sample XML data for the third code example.

  • The fifth code example demonstrates how to use the TreeView control for site navigation by binding it to a SiteMapDataSource control.

  • The sixth code example provides sample site map data for the fifth code example.

  • The seventh code example demonstrates how to populate the nodes in the TreeView control from the client.

The following code example demonstrates how to set up the frames for the following code example.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>TreeView Frameset Example</title>
</head>

    <frameset cols="30%, 75%">

        <frame title="MenuFrame" name="Menu" src="TreeViewFramecs.aspx"/>
        <frame title="ContentFrame" name="Content" src="Home.aspx"/> 

    </frameset>      

</html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>TreeView Frameset Example</title>
</head>

    <frameset cols="30%, 75%">

        <frame title="MenuFrame" name="Menu" src="TreeViewFramevb.aspx"/>
        <frame title="ContentFrame" name="Content" src="Home.aspx"/> 

    </frameset>      

</html>

The following code example demonstrates how to use declarative syntax to display static data in the TreeView control. This example is used within the frame set of the preceding example to display a table of contents.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView Declarative Syntax Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView Declarative Syntax Example</h3>

      <asp:TreeView id="SampleTreeView" 
        runat="server">

        <Nodes>

          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">

            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">

              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>

            </asp:TreeNode>              

            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">

            </asp:TreeNode> 

          </asp:TreeNode>

        </Nodes>

      </asp:TreeView>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView Declarative Syntax Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView Declarative Syntax Example</h3>

      <asp:TreeView id="SampleTreeView" 
        runat="server">

        <Nodes>

          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">

            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">

              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>

            </asp:TreeNode>              

            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">

            </asp:TreeNode> 

          </asp:TreeNode>

        </Nodes>

      </asp:TreeView>

    </form>
  </body>
</html>

The following code example demonstrates how to bind the TreeView control to an XML data source. For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named Book.xml.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView XML Data Binding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView XML Data Binding Example</h3>

      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">

        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>

      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView XML Data Binding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView XML Data Binding Example</h3>

      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">

        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>

      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>

    </form>
  </body>
</html>

The following code example provides sample XML data for the preceding example.

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
        <Section Heading="Section 1">
        </Section>
        <Section Heading="Section 2">
        </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
</Book>

The following code example demonstrates how to use the TreeView control for site navigation by binding it to a SiteMapDataSource control. For this example to work correctly, you must copy the sample site map data, provided after this code example, to a file named Web.sitemap.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView AutoGenerateBindings Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView AutoGenerateBindings Example</h3>

      <!-- Set the AutoGenerateBindings property -->
      <!-- to false declaratively to allow for   -->
      <!-- the user-defined Bindings collection. -->
      <asp:TreeView id="SiteTreeView" 
        DataSourceID="SiteMapSource"
        AutoGenerateDataBindings="False"
        runat="server">

        <DataBindings>

          <asp:TreeNodeBinding TextField="title" NavigateUrlField="url"/>

        </DataBindings>

      </asp:TreeView>

      <asp:SiteMapDataSource ID="SiteMapSource" runat="server"/>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView AutoGenerateBindings Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView AutoGenerateBindings Example</h3>

      <!-- Set the AutoGenerateBindings property -->
      <!-- to false declaratively to allow for   -->
      <!-- the user-defined Bindings collection. -->
      <asp:TreeView id="SiteTreeView" 
        DataSourceID="SiteMapSource"
        AutoGenerateDataBindings="False"
        runat="server">

        <DataBindings>

          <asp:TreeNodeBinding TextField="title" NavigateUrlField="url"/>

        </DataBindings>

      </asp:TreeView>

      <asp:SiteMapDataSource ID="SiteMapSource" runat="server"/>

    </form>
  </body>
</html>

The following code example provides sample site map data for the preceding code example.

<siteMap>
    <siteMapNode title="Home" description="Home" url="default.aspx">
        <siteMapNode title="Products" description="Products" url="Products.aspx">
            <siteMapNode title="Computers" url="Computers.aspx"/>
            <siteMapNode title="Accessories" url="Accessories.aspx"/>     
        </siteMapNode>
    </siteMapNode>
</siteMap>

The following code example demonstrates how to populate the nodes in the TreeView control from the client. When client-side node population is enabled, nodes are populated dynamically on the client, without the need to post back to the server.


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void PopulateNode(Object sender, TreeNodeEventArgs e)
  {

    // Call the appropriate method to populate a node at a particular level.
    switch(e.Node.Depth)
    {
      case 0:
        // Populate the first-level nodes.
        PopulateCategories(e.Node);
        break;
      case 1:
        // Populate the second-level nodes.
        PopulateProducts(e.Node);
        break;
      default:
        // Do nothing.
        break;
    }

  }

  void PopulateCategories(TreeNode node)
  {

    // Query for the product categories. These are the values
    // for the second-level nodes.
    DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories");

    // Create the second-level nodes.
    if(ResultSet.Tables.Count > 0)
    {

      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {

        // Create the new node. Notice that the CategoryId is stored in the Value property 
        // of the node. This will make querying for items in a specific category easier when
        // the third-level nodes are created. 
        TreeNode newNode = new TreeNode();
        newNode.Text = row["CategoryName"].ToString(); 
        newNode.Value = row["CategoryID"].ToString();        

        // Set the PopulateOnDemand property to true so that the child nodes can be 
        // dynamically populated.
        newNode.PopulateOnDemand = true;

        // Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand;

        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode);

      }

    }

  }

  void PopulateProducts(TreeNode node)
  {

    // Query for the products of the current category. These are the values
    // for the third-level nodes.
    DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value);

    // Create the third-level nodes.
    if(ResultSet.Tables.Count > 0)
    {

      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {

        // Create the new node.
        TreeNode NewNode = new TreeNode(row["ProductName"].ToString());

        // Set the PopulateOnDemand property to false, because these are leaf nodes and
        // do not need to be populated.
        NewNode.PopulateOnDemand = false;

        // Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None;

        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode);

      }

    }

  }

  DataSet RunQuery(String QueryString)
  {

    // Declare the connection string. This example uses Microsoft SQL Server 
    // and connects to the Northwind sample database.
    String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI"; 

    SqlConnection DBConnection = new SqlConnection(ConnectionString);
    SqlDataAdapter DBAdapter;
    DataSet ResultsDataSet = new DataSet();

    try
    {

      // Run the query and create a DataSet.
      DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
      DBAdapter.Fill(ResultsDataSet);

      // Close the database connection.
      DBConnection.Close();

    }
    catch(Exception ex)
    {

      // Close the database connection if it is still open.
      if(DBConnection.State == ConnectionState.Open)
      {
        DBConnection.Close();
      }

      Message.Text = "Unable to connect to the database.";

    }

    return ResultsDataSet;

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView PopulateNodesFromClient Example</h3>

      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">

        <Nodes>

          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>

        </Nodes>

      </asp:TreeView>

      <br /><br />

      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs)

    ' Call the appropriate method to populate a node at a particular level.
    Select Case e.Node.Depth

      Case 0
        ' Populate the first-level nodes.
        PopulateCategories(e.Node)

      Case 1
        ' Populate the second-level nodes.
        PopulateProducts(e.Node)

      Case Else
        ' Do nothing.

    End Select

  End Sub

  Sub PopulateCategories(ByVal node As TreeNode)

    ' Query for the product categories. These are the values
    ' for the second-level nodes.
    Dim ResultSet As DataSet = RunQuery("Select CategoryID, CategoryName From Categories")

    ' Create the second-level nodes.
    If ResultSet.Tables.Count > 0 Then

      ' Iterate through and create a new node for each row in the query results.
      ' Notice that the query results are stored in the table of the DataSet.
      Dim row As DataRow

      For Each row In ResultSet.Tables(0).Rows

        ' Create the new node. Notice that the CategoryId is stored in the Value property 
        ' of the node. This will make querying for items in a specific category easier when
        ' the third-level nodes are created. 
        Dim newNode As TreeNode = New TreeNode()
        Newnode.Text = row("CategoryName").ToString() 
        Newnode.Value = row("CategoryID").ToString()

        ' Set the PopulateOnDemand property to true so that the child nodes can be 
        ' dynamically populated.
        newNode.PopulateOnDemand = True

        ' Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand

        ' Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode)

      Next

    End If

  End Sub

  Sub PopulateProducts(ByVal node As TreeNode)

    ' Query for the products of the current category. These are the values
    ' for the third-level nodes.
    Dim ResultSet As DataSet = RunQuery("Select ProductName From Products Where CategoryID=" & node.Value)

    ' Create the third-level nodes.
    If ResultSet.Tables.Count > 0 Then

      ' Iterate through and create a new node for each row in the query results.
      ' Notice that the query results are stored in the table of the DataSet.
      Dim row As DataRow

      For Each row In ResultSet.Tables(0).Rows

        ' Create the new node.
        Dim NewNode As TreeNode = New TreeNode(row("ProductName").ToString())

        ' Set the PopulateOnDemand property to false, because these are leaf nodes and
        ' do not need to be populated.
        NewNode.PopulateOnDemand = False

        ' Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None

        ' Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode)

      Next

    End If

  End Sub

  Function RunQuery(ByVal QueryString As String) As DataSet

    ' Declare the connection string. This example uses Microsoft SQL Server 
    ' and connects to the Northwind sample database.
    Dim ConnectionString As String = "server=localhost;database=NorthWind;Integrated Security=SSPI"

    Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString)
    Dim DBAdapter As SqlDataAdapter
    Dim ResultsDataSet As DataSet = New DataSet

    Try

      ' Run the query and create a DataSet.
      DBAdapter = New SqlDataAdapter(QueryString, DBConnection)
      DBAdapter.Fill(ResultsDataSet)

      ' Close the database connection.
      DBConnection.Close()

    Catch ex As Exception

      ' Close the database connection if it is still open.
      If DBConnection.State = ConnectionState.Open Then

        DBConnection.Close()

      End If

      Message.Text = "Unable to connect to the database."

    End Try

    Return ResultsDataSet

  End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView PopulateNodesFromClient Example</h3>

      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">

        <Nodes>

          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>

        </Nodes>

      </asp:TreeView>

      <br /><br />

      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>
.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top