Export (0) Print
Expand All

ImageField.DataImageUrlField Property

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.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[TypeConverterAttribute("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string DataImageUrlField { get; set; }

Property Value

Type: System.String
The name of the field to bind to the ImageUrl property of each image in an ImageField object.

Use the DataImageUrlField property to specify the name of the field to bind to the ImageUrl property of each image in an ImageField object. The specified field must contain the URLs for the images to display in the ImageField object. You can optionally format the URL values by setting the DataImageUrlFormatString property.

NoteNote

When the filed value is null, an image cannot be displayed. You can display an alternate image for null field values by setting the NullImageUrl property. Instead of an alternate image, you can display alternate text by setting the NullDisplayText property.

The following example code demonstrates how to use the DataImageUrlField property to specify the name of the field to bind to the ImageUrl property of each image in an ImageField object.


<%@ 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="LastName"
            dataimageurlformatstring="~\Images\{0}.jpg"
            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] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </form>
  </body>
</html>

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft