TreeNodeBindingCollection.Item[Int32] Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta l'oggetto TreeNodeBinding in corrispondenza dell'indice specificato nell'oggetto TreeNodeBindingCollection .
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
Parametri
- i
- Int32
Indice in base zero dell'oggetto TreeNodeBinding da recuperare.
Valore della proprietà
Oggetto TreeNodeBinding in corrispondenza dell'indice specificato nell'oggetto TreeNodeBindingCollection.
Esempio
Nell'esempio di codice seguente viene illustrato come usare l'indicizzatore Item[] per accedere agli elementi contenuti in un TreeNodeBindingCollection oggetto . L'oggetto TreeNodeBinding per i nodi di terzo livello viene aggiornato a livello di codice con nuovi valori. Affinché questo esempio funzioni correttamente, è necessario copiare i dati XML che si trovano alla fine di questa sezione in un file denominato 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>
Di seguito sono riportati i dati XML per l'esempio di codice precedente.
<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>
Commenti
Utilizzare l'indicizzatore Item[] per accedere a un TreeNodeBinding oggetto dall'oggetto in corrispondenza TreeNodeBindingCollection dell'utilizzo i della notazione di matrice. L'indicizzatore Item[] consente di modificare o sostituire direttamente un TreeNodeBinding oggetto nell'insieme.