TreeNodeBinding.NavigateUrl Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit l’URL vers laquelle lier lorsqu’un nœud auquel l’objet TreeNodeBinding est appliqué est cliqué.
public:
property System::String ^ NavigateUrl { System::String ^ get(); void set(System::String ^ value); };
public string NavigateUrl { get; set; }
member this.NavigateUrl : string with get, set
Public Property NavigateUrl As String
Valeur de propriété
URL à lier lorsqu’un nœud auquel l’objet TreeNodeBinding est appliqué est cliqué. La valeur par défaut est une chaîne vide (« »), qui indique que la NavigateUrl propriété n’est pas définie.
Exemples
Cette section contient deux exemples de code. Le premier exemple de code montre comment utiliser la NavigateUrl propriété pour spécifier l’URL à lier lorsqu’un nœud auquel l’objet TreeNodeBinding est appliqué est cliqué. Le deuxième exemple de code fournit des exemples de données XML pour le premier exemple de code.
L’exemple de code suivant montre comment utiliser la NavigateUrl propriété pour spécifier l’URL à laquelle lier lorsqu’un nœud auquel l’objet TreeNodeBinding est appliqué est cliqué. 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 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 NavigateUrl propriété pour spécifier l’URL à lier à la NavigateUrl propriété d’un TreeNode objet. Cette relation de liaison affecte tous les TreeNode objets auxquels l’objet TreeNodeBinding est appliqué. Lorsque cette propriété est définie, le TreeView contrôle affiche un lien hypertexte pour le texte du nœud, au lieu de texte brut. Vous pouvez également définir la Target propriété pour spécifier la fenêtre ou le cadre dans lequel afficher le contenu lié.
Note
Vous pouvez remplacer de manière sélective la NavigateUrl propriété en définissant la NavigateUrl propriété de chaque nœud directement.
Au lieu d’utiliser la NavigateUrl propriété pour lier la même URL à chaque nœud, vous pouvez lier la NavigateUrl propriété d’un TreeNode objet à un champ d’une source de données en définissant la NavigateUrlField propriété.
La valeur de cette propriété est stockée dans l’état d’affichage.