Bagikan melalui


TreeNodeBinding.ImageUrl Properti

Definisi

Mendapatkan atau mengatur URL ke gambar yang ditampilkan di samping simpul tempat TreeNodeBinding objek diterapkan.

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

Nilai Properti

URL ke gambar yang ditampilkan di samping simpul tempat TreeNodeBinding objek diterapkan. Si

ImageUrl properti tidak diatur.

Contoh

Bagian ini berisi dua contoh kode. Contoh kode pertama menunjukkan cara menggunakan Depth properti untuk menerapkan TreeNodeBinding objek pada kedalaman simpul tertentu. Contoh kode kedua menyediakan contoh data XML untuk contoh kode pertama.

Contoh kode berikut menunjukkan cara menggunakan ImageUrl properti untuk menentukan gambar kustom untuk simpul tempat TreeNodeBinding objek diterapkan. Agar contoh ini berfungsi dengan benar, Anda harus menyalin data XML sampel, yang disediakan setelah contoh kode ini, ke file bernama 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>

Contoh kode berikut menyediakan contoh data XML untuk contoh sebelumnya.

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

Keterangan

TreeView Saat kontrol terikat ke sumber data, gunakan ImageUrl properti untuk menentukan gambar kustom untuk mengikat ImageUrl properti TreeNode objek. Hubungan pengikatan ini memengaruhi semua TreeNode objek tempat TreeNodeBinding objek diterapkan. Gambar ditampilkan di samping simpul dan dapat dalam format file apa pun (.jpg, .gif, .bmp, dan sebagainya), selama browser klien mendukung format tersebut.

Nota

Anda dapat mengambil alih gambar untuk simpul individual dengan mengatur propertinya ImageUrl secara langsung.

Alih-alih menggunakan properti ini untuk mengikat gambar yang sama ke setiap simpul, Anda dapat mengikat ImageUrl properti TreeNode objek ke bidang sumber data dengan mengatur ImageUrlField properti .

Saat menampilkan gambar di samping simpul dengan ImageUrl properti , Anda juga harus mempertimbangkan untuk mengatur ImageToolTip properti . Teks TipsAlat yang Anda tentukan menyediakan perangkat Teknologi Bantuan dengan deskripsi gambar yang dapat digunakan untuk membuat kontrol lebih mudah diakses.

Nilai properti ini disimpan dalam status tampilan.

Berlaku untuk

Lihat juga