Export (0) Print
Expand All

TreeView.AutoGenerateDataBindings Property

Note: This property is new in the .NET Framework version 2.0.

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

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

public bool AutoGenerateDataBindings { get; set; }
/** @property */
public boolean get_AutoGenerateDataBindings ()

/** @property */
public void set_AutoGenerateDataBindings (boolean value)

public function get AutoGenerateDataBindings () : boolean

public function set AutoGenerateDataBindings (value : boolean)

Property Value

true to have the TreeView control automatically generate tree node bindings; otherwise, false. The default is true.

Tree node bindings define the relationship between a data item and the node it is binding to. When binding to a data source where each data item contains multiple properties (such as an XML element with several attributes), the TreeView control needs to know which data item property to bind to which TreeNode property. If the AutoGenerateDataBindings property is set to true, the TreeView control automatically generates default tree node bindings that set the Text property of the TreeNode object that is associated with the binding to the value that is returned by the ToString method of the data item.

NoteNote

The automatically generated tree node bindings are not added to the DataBindings collection.

In the case of an XML element, the value that is returned by the ToString method is the element name, which shows the underlying structure of the XML file, but is not very useful otherwise. To create a more useful tree, you must define your own tree node bindings by populating the DataBindings collection.

NoteNote

If you define a DataBindings collection, the TreeView control uses those values instead of automatically generated tree node bindings.

The value of this property is stored in view state.

This section contains two code examples. The first code example demonstrates how to disable automatic tree node binding generation by setting the AutoGenerateDataBindings property to false. The second code example provides sample site map data for the first code example.

The following code example demonstrates how to disable automatic tree node binding generation by setting the AutoGenerateDataBindings property to false. A DataBindings collection is then defined to establish the relationship between the data items in a SiteMapDataSource control and the nodes of the TreeView 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#" %>

<html>
  <body>
    <form 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 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft