Export (0) Print
Expand All

TreeView.MaxDataBindDepth Property

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

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

public int MaxDataBindDepth { get; set; }
/** @property */
public int get_MaxDataBindDepth ()

/** @property */
public void set_MaxDataBindDepth (int value)

public function get MaxDataBindDepth () : int

public function set MaxDataBindDepth (value : int)

Not applicable.

Property Value

The maximum number of tree levels to bind to the TreeView control. The default is -1, which binds all the tree levels in the data source to the control.

Exception typeCondition

ArgumentOutOfRangeException

The selected value is less than -1.

When binding the TreeView control to a data source, use the MaxDataBindDepth property to limit the number of tree levels to bind to the control. For example, setting this property to 2 binds only the root node and any nodes that are immediately under the root node to the TreeView control. All remaining nodes in the data source are ignored.

Security noteSecurity 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 MaxDataBindDepth property to hide data.

The value of this property is stored in view state.

This section contains two code examples. The first code example demonstrates how to use the MaxDataBindDepth property to bind only the first two node levels (depths 0 and 1) to the TreeView control. The second code example provides sample XML data for the first code example.

The following code example demonstrates how to use the MaxDataBindDepth property to bind only the first two node levels (depths 0 and 1) to the TreeView control. All node levels in the data source are ignored. 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 MaxDataBindDepth Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView MaxDataBindDepth Example</h3>
    
      <asp:TreeView id="BookTreeView"
        MaxDataBindDepth="1"  
        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 code 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>

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft