Image.ImageUrl 屬性

定義

取得或設定 URL,這個 URL 提供要顯示於 Image 控制項中之影像的路徑。Gets or sets the URL that provides the path to an image to display in the Image control.

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 控制項中之影像的路徑。The URL that provides the path to an image to display in the Image control.

屬性

範例

下列範例示範如何使用 ImageUrl 屬性來指定要在控制項中顯示之影像的位置 ImageThe following example demonstrates how to use the ImageUrl property to specify the location of the image to display in the Image control.

<%@ 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 可以使用屬性來指定要在控制項中顯示之影像的 URL ImageUse the ImageUrl property to specify the URL of an image to display in the Image control. 您可以使用相對或絕對 URL。You can use a relative or an absolute URL. 相對 URL 會將影像的位置與網頁的位置產生關聯,而不需要在伺服器上指定完整的路徑。A relative URL relates the location of the image to the location of the Web page without specifying a complete path on the server. 相對於網頁位置的路徑。The path is relative to the location of the Web page. 這可讓您更輕鬆地將整個網站移至伺服器上的其他目錄,而不需要更新程式碼。This makes it easier to move the entire site to another directory on the server without updating the code. 絕對 URL 會提供完整的路徑,因此將網站移至另一個目錄需要您更新程式碼。An absolute URL provides the complete path, so moving the site to another directory requires that you update the code.

適用於