TreeNodeBindingCollection.Insert(Int32, TreeNodeBinding) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定的 TreeNodeBinding 对象插入 TreeNodeBindingCollection 对象中的指定索引位置。
public:
void Insert(int index, System::Web::UI::WebControls::TreeNodeBinding ^ binding);
public void Insert (int index, System.Web.UI.WebControls.TreeNodeBinding binding);
member this.Insert : int * System.Web.UI.WebControls.TreeNodeBinding -> unit
Public Sub Insert (index As Integer, binding As TreeNodeBinding)
参数
- index
- Int32
要插入 TreeNodeBinding 对象的从零开始的索引位置。
- binding
- TreeNodeBinding
要插入的 TreeNodeBinding。
示例
下面的代码示例演示如何使用Insert该方法以编程方式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 RemoveAt method to remove the TreeNodeBinding object
// for the third-level nodes (index 2).
BookTreeView.DataBindings.RemoveAt(2);
// Create a new TreeNodeBinding object and set its properties.
TreeNodeBinding newBinding = new TreeNodeBinding();
newBinding.DataMember = "Section";
newBinding.TextField = "Subject";
// Use the Insert method to insert the TreeNodeBinding object
// into the DaaBindings collection at index 2.
BookTreeView.DataBindings.Insert(2, newBinding);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeBindingCollection Insert and RemoveAt Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeBindingCollection Insert and RemoveAt 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 RemoveAt method to remove the TreeNodeBinding object
' for the third-level nodes (index 2).
BookTreeView.DataBindings.RemoveAt(2)
' Create a new TreeNodeBinding object and set its properties.
Dim newBinding As TreeNodeBinding = New TreeNodeBinding
newBinding.DataMember = "Section"
newBinding.TextField = "Subject"
' Use the Insert method to insert the TreeNodeBinding object to
' the DataBindings collection at index 2.
BookTreeView.DataBindings.Insert(2, newBinding)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeBindingCollection Insert and RemoveAt Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeBindingCollection Insert and RemoveAt 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>
注解
使用该方法将 Insert 指定的 TreeNodeBinding 对象插入到 TreeNodeBindingCollection 对象中 index
。
或者,可以将对象TreeNodeBinding追加到使用Add该方法的TreeNodeBindingCollection末尾。