TreeView.MaxDataBindDepth Propriedade
Definição
public:
property int MaxDataBindDepth { int get(); void set(int value); };
public int MaxDataBindDepth { get; set; }
member this.MaxDataBindDepth : int with get, set
Public Property MaxDataBindDepth As Integer
Valor da propriedade
O número máximo de níveis de árvore a serem associados ao TreeView controle.The maximum number of tree levels to bind to the TreeView control. O padrão é-1, que associa todos os níveis de árvore na fonte de dados ao controle.The default is -1, which binds all the tree levels in the data source to the control.
Exceções
O valor selecionado é menor que -1.The selected value is less than -1.
Exemplos
Esta seção contém dois exemplos de código.This section contains two code examples. O primeiro exemplo de código demonstra como usar a MaxDataBindDepth propriedade para associar apenas os dois primeiros níveis de nó (profundidades 0 e 1) ao TreeView controle.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. O segundo exemplo de código fornece dados XML de exemplo para o primeiro exemplo de código.The second code example provides sample XML data for the first code example.
O exemplo de código a seguir demonstra como usar a MaxDataBindDepth propriedade para associar apenas os dois primeiros níveis de nó (profundidades 0 e 1) ao TreeView controle.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. Todos os níveis de nó na fonte de dados são ignorados.All node levels in the data source are ignored. Para que este exemplo funcione corretamente, você deve copiar os dados XML de exemplo, fornecidos após este exemplo de código, para um arquivo chamado Book.xml.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>
<%@ 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 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>
O exemplo de código a seguir fornece dados XML de exemplo para o exemplo de código anterior.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>
Comentários
Ao ligar o TreeView controle a uma fonte de dados, use a MaxDataBindDepth propriedade para limitar o número de níveis de árvore a serem associados ao controle.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. Por exemplo, definir essa propriedade para 2 associar somente o nó raiz e os nós que estão imediatamente sob o nó raiz ao TreeView controle.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. Todos os nós restantes na fonte de dados são ignorados.All remaining nodes in the data source are ignored.
Importante
Um usuário mal-intencionado pode criar uma solicitação de retorno de chamada e obter dados para os nós do TreeView controle que o desenvolvedor da página não está exibindo.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. Portanto, a segurança dos dados deve ser implementada pela fonte de dados.Therefore, security of the data must be implemented by the data source. Não use a MaxDataBindDepth propriedade para ocultar dados.Do not use the MaxDataBindDepth property to hide data.
O valor dessa propriedade é armazenado em estado de exibição.The value of this property is stored in view state.