TreeNodeBindingCollection.Item[Int32] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 TreeNodeBinding 物件在物件中 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
參數
- i
- Int32
取回的零基索引 TreeNodeBinding 。
屬性值
在 中指定的索引 TreeNodeBinding處 。TreeNodeBindingCollection
範例
以下程式碼範例示範如何使用 Item[] 索引器存取物件中的 TreeNodeBindingCollection 項目。 TreeNodeBinding第三層節點的物件會以程式方式更新,新增值。 為了讓這個範例正確運作,你必須將本節末尾的 XML 資料複製到一個名為 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>
以下是前述程式碼範例的 XML 資料。
<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>
備註
使用Item[]索引器使用陣列符號,從位於 的TreeNodeBinding物件中存取物件。TreeNodeBindingCollectioni
Item[]索引器允許你直接修改或替換集合中的物件TreeNodeBinding。