ImageField 类

定义

表示将显示为数据绑定控件中的图像的字段。Represents a field that is displayed as an image in a data-bound control.

public ref class ImageField : System::Web::UI::WebControls::DataControlField
public class ImageField : System.Web.UI.WebControls.DataControlField
type ImageField = class
    inherit DataControlField
Public Class ImageField
Inherits DataControlField
继承

示例

下面的示例演示如何使用ImageField GridView控件中的对象来显示图像。The following example demonstrates how to use an ImageField object in a GridView control to display an 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 runat="server">
    <title>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </asp:gridview>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </asp:gridview>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

注解

数据绑定控件( GridView如和DetailsView)使用类来显示每个显示的记录的图像。ImageFieldThe ImageField class is used by data-bound controls (such as GridView and DetailsView) to display an image for each record displayed. ImageField对象的显示方式取决于使用它的数据绑定控件。The ImageField object is displayed differently depending on the data-bound control in which it is used. 例如, GridView控件以列的形式ImageField显示对象,而DetailsView控件则将其显示为一行。For example, the GridView control displays an ImageField object as a column, while the DetailsView control displays it as a row.

若要显示图像,必须将ImageField对象从包含图像 URL 的数据源绑定到字段。To display images, you must bind an ImageField object to a field from a data source that contains the URL of an image. 这是通过设置DataImageUrlField属性来完成的。This is accomplished by setting the DataImageUrlField property. 可以使用DataImageUrlFormatString属性设置 URL 值的格式。The URL value can be formatted by using the DataImageUrlFormatString property. 每个图像还可以有与之关联的替代文本。Each image can also have alternate text associated with it. 当图像无法加载或不可用时,将显示此文本。This text is displayed when an image cannot be loaded, or is unavailable. 支持工具提示功能的浏览器还会将此文本显示为工具提示。Browsers that support the ToolTips feature also display this text as a ToolTip. 您可以使用下列方法之一为显示的图像指定替代文本:You can specify the alternate text for a displayed image by using one of the following methods:

如果图像的 URL 值为null,则无法显示图像。When the URL value for an image is null, an image cannot be displayed. 您可以通过NullImageUrl设置属性来显示null字段值的替换图像。You can display an alternate image for null field values by setting the NullImageUrl property. 可以通过设置NullDisplayText属性来显示替换文本,而不是使用备用图像。Instead of an alternate image, you can display alternate text by setting the NullDisplayText property.

默认情况下,所有声明的字段都显示在数据绑定控件中。By default, all declared fields are displayed in a data-bound control. 可以通过ImageField Visible将属性设置为来false隐藏数据绑定控件中的对象。You can hide an ImageField object in a data-bound control by setting the Visible property to false.

您可以自定义ImageField对象的页眉和页脚部分。You can customize the header and footer sections of an ImageField object. 若要在页眉或页脚部分显示标题,请分别设置HeaderTextFooterText属性。To display a caption in the header or footer section, set the HeaderText or FooterText properties, respectively. 若要在页眉节而不是文本中显示图像,请HeaderImageUrl设置属性。To display an image in the header section instead of text, set the HeaderImageUrl property. 通过ImageField false将属性设置为,可以在对象中隐藏标头部分。 ShowHeaderThe header section can be hidden in the ImageField object by setting the ShowHeader property to false.

备注

某些数据绑定控件(如GridView控件)只能显示或隐藏控件的整个标题部分。Some data-bound controls (such as the GridView control) can show or hide only the entire header section of the control. 这些数据绑定控件不支持单个数据绑定ShowHeader字段的属性。These data-bound controls do not support the ShowHeader property for an individual data-bound field. 若要显示或隐藏数据绑定控件的整个标头部分,请使用控件的ShowHeader属性(如果可用)。To show or hide the entire header section of a data-bound control, use the control's ShowHeader property (if available).

还可以通过设置字段的不同部分ImageField的样式属性来自定义对象(字体颜色、背景色等)的外观。You also can customize the appearance of the ImageField object (font color, background color, and so on) by setting the style properties for the different parts of the field. 下表列出了不同的样式属性。The following table lists the different style properties.

Style 属性Style property 说明Description
ControlStyle ImageField对象的子 Web 服务器控件的样式设置。The style settings for the child Web server controls of the ImageField object.
FooterStyle ImageField对象的脚注部分的样式设置。The style settings for the footer section of the ImageField object.
HeaderStyle ImageField对象的标头部分的样式设置。The style settings for the header section of the ImageField object.
ItemStyle ImageField对象中数据项的样式设置。The style settings for the data items in the ImageField object.

构造函数

ImageField()

初始化 ImageField 类的新实例。Initializes a new instance of the ImageField class.

字段

ThisExpression

表示“this”表达式。Represents the "this" expression.

属性

AccessibleHeaderText

获取或设置某些控件中呈现为 AbbreviatedText 属性值的文本。Gets or sets text that is rendered as the AbbreviatedText property value in some controls.

(继承自 DataControlField)
AlternateText

获取或设置为 ImageField 对象中的图像显示的备用文本。Gets or sets the alternate text displayed for an image in the ImageField object.

Control

获取对数据控件的引用,该控件与 DataControlField 对象关联。Gets a reference to the data control that the DataControlField object is associated with.

(继承自 DataControlField)
ControlStyle

获取 DataControlField 对象所包含的任何 Web 服务器控件的样式。Gets the style of any Web server controls contained by the DataControlField object.

(继承自 DataControlField)
ConvertEmptyStringToNull

获取或设置一个值,用于指示在从数据源返回字段值时,空字符串 ("") 值是否转换为 nullGets or sets a value indicating whether empty string ("") values are converted to null when the field values are returned from the data source.

DataAlternateTextField

获取或设置数据源中某个字段的名称,该字段包含的值要绑定到 AlternateText 对象中每个图像的 ImageField 属性。Gets or sets the name of the field from the data source that contains the values to bind to the AlternateText property of each image in an ImageField object.

DataAlternateTextFormatString

获取或设置一个字符串,该字符串指定 ImageField 对象中每个图像的备用文本所呈现的格式。Gets or sets the string that specifies the format in which the alternate text for each image in an ImageField object is rendered.

DataImageUrlField

获取或设置数据源中某个字段的名称,该字段包含的值要绑定到 ImageUrl 对象中每个图像的 ImageField 属性。Gets or sets the name of the field from the data source that contains the values to bind to the ImageUrl property of each image in an ImageField object.

DataImageUrlFormatString

获取或设置一个字符串,用于指定 ImageField 对象中每个图像的 URL 所呈现的格式。Gets or sets the string that specifies the format in which the URL for each image in an ImageField object is rendered.

DesignMode

获取一个值,该值指示数据控件字段当前是否在设计时环境中进行查看。Gets a value indicating whether a data control field is currently viewed in a design-time environment.

(继承自 DataControlField)
FooterStyle

获取或设置数据控件字段脚注的样式。Gets or sets the style of the footer of the data control field.

(继承自 DataControlField)
FooterText

获取或设置数据控件字段的脚注项中显示的文本。Gets or sets the text that is displayed in the footer item of a data control field.

(继承自 DataControlField)
HeaderImageUrl

获取或设置数据控件字段的标题项中显示的图像的 URL。Gets or sets the URL of an image that is displayed in the header item of a data control field.

(继承自 DataControlField)
HeaderStyle

获取或设置数据控件字段标头的样式。Gets or sets the style of the header of the data control field.

(继承自 DataControlField)
HeaderText

获取或设置数据控件字段的标题项中显示的文本。Gets or sets the text that is displayed in the header item of a data control field.

(继承自 DataControlField)
InsertVisible

获取一个值,该值指示 DataControlField 对象在其父级数据绑定控件处于插入模式时是否可见。Gets a value indicating whether the DataControlField object is visible when its parent data-bound control is in insert mode.

(继承自 DataControlField)
IsTrackingViewState

获取一个值,该值指示 DataControlField 对象是否保存对其视图状态的更改。Gets a value indicating whether the DataControlField object is saving changes to its view state.

(继承自 DataControlField)
ItemStyle

获取由数据控件字段显示的任何基于文本的内容的样式。Gets the style of any text-based content displayed by a data control field.

(继承自 DataControlField)
NullDisplayText

获取或设置当 ImageField 属性所指定的字段值为 null 时,将要显示在 DataImageUrlField 对象中的文本。Gets or sets the text to display in an ImageField object when the value of the field specified by the DataImageUrlField property is null.

NullImageUrl

获取或设置在由 ImageField 属性所指定的字段值为 null 时,DataImageUrlField 对象中所显示的备用图像的 URL。Gets or sets the URL to an alternate image displayed in an ImageField object when the value of the field specified by the DataImageUrlField property is null.

ReadOnly

获取或设置一个值,该值指示是否可以在编辑模式下修改由 DataImageUrlField 属性指定的字段值。Gets or sets a value indicating whether the values of the field specified by the DataImageUrlField property can be modified in edit mode.

ShowHeader

获取或设置一个值,该值指示是否呈现数据控件字段的标题项。Gets or sets a value indicating whether the header item of a data control field is rendered.

(继承自 DataControlField)
SortExpression

获取或设置数据源控件用来对数据进行排序的排序表达式。Gets or sets a sort expression that is used by a data source control to sort data.

(继承自 DataControlField)
ValidateRequestMode

获取或设置一个值,该值指定该控件是否验证客户端输入。Gets or sets a value that specifies whether the control validates client input.

(继承自 DataControlField)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 DataControlField 对象的视图状态。Gets a dictionary of state information that allows you to save and restore the view state of a DataControlField object across multiple requests for the same page.

(继承自 DataControlField)
Visible

获取或设置指示是否呈现数据控件字段的值。Gets or sets a value indicating whether a data control field is rendered.

(继承自 DataControlField)

方法

CloneField()

创建当前 DataControlField 派生对象的副本。Creates a duplicate copy of the current DataControlField-derived object.

(继承自 DataControlField)
CopyProperties(DataControlField)

将当前 ImageField 对象的属性复制到指定对象。Copies the properties of the current ImageField object to the specified object.

CreateField()

返回 ImageField 类的新实例。Returns a new instance of the ImageField class.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
ExtractValuesFromCell(IOrderedDictionary, DataControlFieldCell, DataControlRowState, Boolean)

使用指定的 IOrderedDictionary 对象中的值填充指定的 DataControlFieldCell 对象。Fills the specified IOrderedDictionary object with the values from the specified DataControlFieldCell object.

FormatImageUrlValue(Object)

DataImageUrlFormatString 属性所指定的格式应用于字段值。Applies the format specified by the DataImageUrlFormatString property to a field value.

GetDesignTimeValue()

在设计器中呈现 ImageField 对象时,检索用作字段值的值。Retrieves the value used for a field's value when rendering the ImageField object in a designer.

GetFormattedAlternateText(Control)

DataAlternateTextFormatString 属性所指定的格式应用于包含在指定对象 Control 中的备用文本值。Applies the format specified by the DataAlternateTextFormatString property to the alternate text value contained in the specified Control object.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetValue(Control, String, PropertyDescriptor)

从指定控件检索指定字段的值。Retrieves the value of the specified field from the specified control.

Initialize(Boolean, Control)

初始化 ImageField 对象。Initializes the ImageField object.

InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32)

使用指定单元格类型、行状态和行索引初始化指定的 DataControlFieldCell 对象。Initializes the specified DataControlFieldCell object with the specified cell type, row state, and row index.

InitializeDataCell(DataControlFieldCell, DataControlRowState)

使用指定的行状态初始化指定的 DataControlFieldCell 对象。Initializes the specified DataControlFieldCell object with the specified row state.

LoadViewState(Object)

将数据源视图还原为保存过的前一视图状态。Restores the data source view's previously saved view state.

(继承自 DataControlField)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnDataBindField(Object, EventArgs)

将字段值绑定到 ImageField 对象。Binds the value of a field to the ImageField object.

OnFieldChanged()

引发 FieldChanged 事件。Raises the FieldChanged event.

(继承自 DataControlField)
SaveViewState()

保存在页回发到服务器后对 DataControlField 视图状态所做的更改。Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(继承自 DataControlField)
ToString()

返回表示此 DataControlField 对象的字符串。Returns a string that represents this DataControlField object.

(继承自 DataControlField)
TrackViewState()

使 DataControlField 对象跟踪对其视图状态所做的更改,以便这些更改可以存储在控件的 ViewState 属性中并且能够在同一页的不同请求间得以保持。Causes the DataControlField object to track changes to its view state so they can be stored in the control's ViewState property and persisted across requests for the same page.

(继承自 DataControlField)
ValidateSupportsCallback()

确定 ImageField 对象中所包含的控件是否支持回调。Determines whether the controls contained in an ImageField object support callbacks.

显式界面实现

IDataSourceViewSchemaAccessor.DataSourceViewSchema

获取或设置与此 DataControlField 对象关联的架构。Gets or sets the schema associated with this DataControlField object.

(继承自 DataControlField)
IStateManager.IsTrackingViewState

获取一个值,该值指示 DataControlField 对象是否保存对其视图状态的更改。Gets a value indicating whether the DataControlField object is saving changes to its view state.

(继承自 DataControlField)
IStateManager.LoadViewState(Object)

将数据控件字段还原为保存过的前一视图状态。Restores the data control field's previously saved view state.

(继承自 DataControlField)
IStateManager.SaveViewState()

保存在页回发到服务器后对 DataControlField 视图状态所做的更改。Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(继承自 DataControlField)
IStateManager.TrackViewState()

使 DataControlField 对象跟踪对其视图状态所做的更改,以便这些更改可以存储在控件的 ViewState 属性中并且能够在同一页的不同请求间得以保持。Causes the DataControlField object to track changes to its view state so they can be stored in the control's ViewState property and persisted across requests for the same page.

(继承自 DataControlField)

适用于

另请参阅