TreeNodeBinding.Text Propriété

Définition

Obtient ou définit le texte qui est affiché pour le nœud auquel l'objet TreeNodeBinding est appliqué.

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

Valeur de propriété

Texte affiché pour le nœud auquel l'objet TreeNodeBinding est appliqué. La valeur par défaut est une chaîne vide ("").

Exemples

Cette section contient deux exemples de code. Le premier exemple de code montre comment utiliser la Text propriété pour spécifier la valeur à afficher pour un nœud auquel l’objet TreeNodeBinding est appliqué. Le deuxième exemple de code fournit des exemples de données XML pour le premier exemple de code.

L’exemple suivant montre comment utiliser la Text propriété pour spécifier la valeur à afficher pour un nœud auquel l’objet TreeNodeBinding est appliqué. Pour que cet exemple fonctionne correctement, vous devez copier l’exemple de données XML, fourni après cet exemple de code, dans un fichier nommé Booklist.xml.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeViewBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeViewBinding Example</h3>
    
      <!-- Set the Text, ImageUrl, ImageToolTip, -->
      <!-- NavigateUrl, Value, and ToolTip       -->
      <!-- properties of a TreeNodeBinding       -->
      <!-- object declaratively.                 -->   
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        Target="_blank" 
        runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Books" 
            Depth="0" 
            TextField="Text"/>
          <asp:TreeNodeBinding DataMember="Book" 
            Depth="1" 
            Text="Book Title" 
            ImageUrl="Image.jpg"
            ImageToolTip="Book Image" 
            NavigateUrl="http://www.microsoft.com" 
            Value="BookID" 
            ToolTip="Book Information"/>
          <asp:TreeNodeBinding DataMember="Description" 
            Depth="2" 
            TextField="Text"/>
          <asp:TreeNodeBinding DataMember="Price" 
            Depth="2" 
            TextField="Value"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Booklist.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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeViewBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeViewBinding Example</h3>
    
      <!-- Set the Text, ImageUrl, ImageToolTip, -->
      <!-- NavigateUrl, Value, and ToolTip       -->
      <!-- properties of a TreeNodeBinding       -->
      <!-- object declaratively.                 -->   
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        Target="_blank" 
        runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Books" 
            Depth="0" 
            TextField="Text"/>
          <asp:TreeNodeBinding DataMember="Book" 
            Depth="1" 
            Text="Book Title" 
            ImageUrl="Image.jpg"
            ImageToolTip="Book Image" 
            NavigateUrl="http://www.microsoft.com" 
            Value="BookID" 
            ToolTip="Book Information"/>
          <asp:TreeNodeBinding DataMember="Description" 
            Depth="2" 
            TextField="Text"/>
          <asp:TreeNodeBinding DataMember="Price" 
            Depth="2" 
            TextField="Value"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Booklist.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

L’exemple de code suivant fournit des exemples de données XML pour l’exemple de code précédent.

<Books Text="Books List">  
    <Book Text="Book Title One"  
        Value="1"   
        Image="Bookimage1.jpg"  
        ImageToolTip="Book 1 Photo"   
        Nav="http://www.microsoft.com"  
        Tip="Book Title 1">  
        <Description Text="Book Description">  
        </Description>  
        <Price Value="$1.99">  
        </Price>  
        <Author Text="Author Name"  
            Value="LastName"   
            Image="Authorimage1.jpg"   
            Nav="http://www.microsoft.com"  
            Tip="Author Name">  
        </Author>  
    </Book>  
    <Book Text="Book Title Two"  
        Value="2"   
        Image="Bookimage2.jpg"  
        ImageToolTip="Book 2 Photo"   
        Nav="http://www.microsoft.com"  
        Tip="Click Me">  
        <Description Text="Book Description">  
        </Description>  
        <Price Value="$2.99">  
        </Price>  
        <Author Text="Author Name"  
            Value="LastName"   
            Image="Authorimage2.jpg"   
            Nav="http://www.microsoft.com"  
            Tip="Author Name">  
        </Author>  
    </Book>  
</Books>  

Remarques

Lorsque le TreeView contrôle est lié à une source de données, utilisez la Text propriété pour spécifier la valeur à lier à la Text propriété d’un TreeNode objet . Cette relation de liaison affecte tous les TreeNode objets auxquels l’objet TreeNodeBinding est appliqué. La Text propriété est utilisée pour spécifier le texte affiché dans un nœud.

Notes

Vous pouvez remplacer la Text propriété de manière sélective en définissant directement la Text propriété de chaque nœud.

Au lieu d’utiliser la Text propriété pour lier le même texte à chaque nœud, vous pouvez lier la Text propriété d’un TreeNode objet à un champ d’une source de données en définissant la TextField propriété .

La valeur de cette propriété est stockée dans l’état d’affichage.

La valeur de cette propriété, lorsqu’elle est définie, peut être enregistrée automatiquement dans un fichier de ressources à l’aide d’un outil de concepteur. Pour plus d’informations, consultez LocalizableAttributeet Globalisation et localisation.

S’applique à

Voir aussi