TreeNodeBindingCollection.Item[Int32] Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define o TreeNodeBinding objeto no índice especificado no TreeNodeBindingCollection objeto.
public:
property System::Web::UI::WebControls::TreeNodeBinding ^ default[int] { System::Web::UI::WebControls::TreeNodeBinding ^ get(int i); void set(int i, System::Web::UI::WebControls::TreeNodeBinding ^ value); };
public System.Web.UI.WebControls.TreeNodeBinding this[int i] { get; set; }
member this.Item(int) : System.Web.UI.WebControls.TreeNodeBinding with get, set
Default Public Property Item(i As Integer) As TreeNodeBinding
Parâmetros
- i
- Int32
O índice baseado em zero do TreeNodeBinding para recuperar.
Valor de Propriedade
O TreeNodeBinding no índice especificado no TreeNodeBindingCollection.
Exemplos
O exemplo de código seguinte demonstra como usar o Item[] indexador para aceder aos itens que estão num TreeNodeBindingCollection objeto. O TreeNodeBinding objeto para os nós de terceiro nível é atualizado programaticamente com novos valores. Para que este exemplo funcione corretamente, deve copiar os dados XML localizados no final desta secção para um ficheiro chamado 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">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Use the indexer to access the TreeNodeBinding object for
// the third-level nodes (index 2) and change the value of
// its TextField property to "Subject".
BookTreeView.DataBindings[2].TextField = "Subject";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeBindingCollection Indexer Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeBindingCollection Indexer 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">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Use the indexer to access the TreeNodeBinding object for
' the third-level nodes (index 2) and change the value of
' its TextField property to "Subject".
BookTreeView.DataBindings(2).TextField = "Subject"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeBindingCollection Indexer Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeBindingCollection Indexer 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>
Segue-se os dados XML para o exemplo de código anterior.
<Book Title="Book Title">
<Chapter Heading="Chapter 1">
<Section Heading="Section 1"
Subject="Subject 1">
</Section>
<Section Heading="Section 2"
Subject="Subject 1">
</Section>
</Chapter>
<Chapter Heading="Chapter 2">
<Section Heading="Section 1"
Subject="Subject 1">
</Section>
</Chapter>
</Book>
Observações
Use o Item[] indexador para aceder a um TreeNodeBinding objeto a partir do TreeNodeBindingCollection objeto localizado em i usando notação em array. O Item[] indexador permite-lhe modificar ou substituir diretamente um TreeNodeBinding objeto na coleção.