TreeNodeBinding.ImageUrlField 屬性

定義

取得或設定欄位來自資料來源之欄位的名稱,以繫結至套用 ImageUrl 物件之 TreeNode 物件的 TreeNodeBinding 物件。

public:
 property System::String ^ ImageUrlField { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ImageUrlField { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ImageUrlField { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ImageUrlField : string with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ImageUrlField : string with get, set
Public Property ImageUrlField As String

屬性值

String

要繫結至已經套用 ImageUrl 物件之 TreeNode 物件的 TreeNodeBinding 屬性的欄位名稱。 預設值是空字串 (""),表示未設定 ImageUrlField 屬性。

屬性

範例

本節包含兩個程式碼範例。 第一個程式碼範例示範如何使用 ImageUrlField 屬性來指定 XML 元素的哪個屬性,以系結至 ImageUrl 套用物件之 TreeNode 物件的 TreeNodeBinding 屬性。 第二個程式碼範例會提供第一個程式碼範例的範例 XML 資料。

下列程式碼範例示範如何使用 ImageUrlField 屬性來指定 XML 元素的哪個屬性,以系結至 ImageUrl 套用物件之 TreeNode 物件的 TreeNodeBinding 屬性。 若要讓此範例正常運作,您必須將此程式碼範例之後提供的範例 XML 資料複製到名為 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 TextField, ImageUrlField, NavigateUrlField, -->
      <!-- ValueField, and ToolTipField 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" 
            TextField="Text" 
            ImageUrlField="Image"
            ImageToolTipField="ImageToolTip" 
            NavigateUrlField="Nav" 
            ValueField="Value" 
            ToolTipField="Tip"/>
          <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 TextField, ImageUrlField, NavigateUrlField, -->
      <!-- ValueField, and ToolTipField 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" 
            TextField="Text" 
            ImageUrlField="Image"
            ImageToolTipField="ImageToolTip" 
            NavigateUrlField="Nav" 
            ValueField="Value" 
            ToolTipField="Tip"/>
          <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>

下列程式碼範例提供上述範例的 XML 資料範例。

<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>  

備註

TreeView 控制項系結至資料來源時,請使用 ImageUrlField 屬性來指定功能變數名稱以系結至 ImageUrl 物件的 屬性 TreeNode 。 這個系結關聯性會影響套用物件的所有 TreeNode 物件 TreeNodeBinding 。 只要用戶端瀏覽器支援格式,影像就會顯示在節點旁邊,而且可以是任何檔案格式 (.jpg、.gif、.bmp等等) 。

注意

您可以直接設定其 ImageUrl 屬性,以覆寫個別節點的映射。

您可以藉由設定 ImageUrl 屬性,將 屬性設定 ImageUrl 為固定值,而不是使用這個屬性將 物件的 屬性 TreeNode 系結 ImageUrl 至欄位。

注意

如果資料來源包含多個欄位,您必須先設定 DepthDataMember 屬性,或兩個屬性才能系結至適當的欄位。

使用 屬性顯示節點 ImageUrlField 旁的影像時,您也應該考慮設定 ImageToolTipField 屬性。 您指定的工具提示文字會提供輔助技術裝置的描述,這些影像可用來讓控制項更容易存取。

這個屬性的值會儲存在檢視狀態中。

適用於

另請參閱