TreeNodeBindingCollection.Add(TreeNodeBinding) Método
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.
Acrescenta o objeto especificado TreeNodeBinding ao final do TreeNodeBindingCollection objeto.
public:
int Add(System::Web::UI::WebControls::TreeNodeBinding ^ binding);
public int Add(System.Web.UI.WebControls.TreeNodeBinding binding);
member this.Add : System.Web.UI.WebControls.TreeNodeBinding -> int
Public Function Add (binding As TreeNodeBinding) As Integer
Parâmetros
- binding
- TreeNodeBinding
O TreeNodeBinding para acrescentar.
Devoluções
O índice em base zero da localização do somado TreeNodeBinding no TreeNodeBindingCollection.
Exemplos
O exemplo de código seguinte demonstra como usar o Add método para adicionar um novo TreeNodeBinding objeto programaticamente a um TreeNodeBindingCollection objeto. 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 Remove method to remove the TreeNodeBinding object
// for the third-level nodes (index 2).
TreeNodeBinding oldBinding = BookTreeView.DataBindings[2];
BookTreeView.DataBindings.Remove(oldBinding);
// Create a new TreeNodeBinding object and set its properties.
TreeNodeBinding newBinding = new TreeNodeBinding();
newBinding.DataMember = "Section";
newBinding.TextField = "Subject";
// Use the Add method to add the TreeNodeBinding object to the
// DataBindings collection.
BookTreeView.DataBindings.Add(newBinding);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeBindingCollection Add and Remove Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeBindingCollection Add and Remove 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 Remove method to remove the TreeNodeBinding object
' for the third-level nodes (index 2).
Dim oldBinding As TreeNodeBinding = BookTreeView.DataBindings(2)
BookTreeView.DataBindings.Remove(oldBinding)
' Create a new TreeNodeBinding object and set its properties.
Dim newBinding As TreeNodeBinding = New TreeNodeBinding
newBinding.DataMember = "Section"
newBinding.TextField = "Subject"
' Use the Add method to add the TreeNodeBinding object to the
' DataBindings collection.
BookTreeView.DataBindings.Add(newBinding)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeBindingCollection Add and Remove Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeBindingCollection Add and Remove 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 Add método para anexar o objeto especificado TreeNodeBinding ao final do TreeNodeBindingCollection objeto.
Como alternativa, pode inserir um TreeNodeBinding objeto num TreeNodeBindingCollection índice específico usando o Insert método.