Image.ImageUrl Image.ImageUrl Image.ImageUrl Image.ImageUrl Property

定义

获取或设置为要在 Image 控件中显示的图像提供路径的 URL。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; }
member this.ImageUrl : string with get, set
Public Overridable Property ImageUrl As String

属性值

为要在 Image 控件中显示的图像提供路径的 URL。The URL that provides the path to an image to display in the Image control.

示例

下面的示例演示如何使用ImageUrl属性指定要Image在控件中显示的图像的位置。The 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>

注解

使用属性指定要在控件中显示的图像的 URL。 Image ImageUrlUse 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.

适用于