Image.ImageUrl 屬性

定義

取得或設定 URL,這個 URL 提供要顯示於 Image 控制項中之影像的路徑。

public:
 virtual property System::String ^ ImageUrl { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public virtual string ImageUrl { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ImageUrl : string with get, set
Public Overridable Property ImageUrl As String

屬性值

String

URL,提供要顯示於 Image 控制項中之影像的路徑。

屬性

範例

下列範例示範如何使用 ImageUrl 屬性來指定要顯示在 控制項中的 Image 影像位置。

<%@ 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>
    <title>Image Example</title>
</head>
 
<body>

   <form id="form1" runat="server">

      <h3>Image Example</h3>

      <asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="images/image1.jpg"/>
  
   </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>
    <title>Image Example</title>
</head>
 
<body>

   <form id="form1" runat="server">

      <h3>Image Example</h3>

      <asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="images/image1.jpg"/>
  
   </form>

</body>
</html>

備註

ImageUrl使用 屬性來指定要顯示在 控制項中的 Image 影像 URL。 您可以使用相對 URL 或絕對 URL。 相對 URL 會將影像的位置與網頁的位置建立關聯,而不指定伺服器上的完整路徑。 路徑相對於網頁的位置。 這可讓您更輕鬆地將整個月臺移至伺服器上的另一個目錄,而不需要更新程式碼。 絕對 URL 會提供完整的路徑,因此將月臺移至另一個目錄需要您更新程式碼。

適用於