ImageField クラスとは? わかりやすく解説

ImageField クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

データ バインド コントロールイメージとして表示するフィールド表します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class ImageField
    Inherits DataControlField
public class ImageField : DataControlField
public ref class ImageField : public
 DataControlField
public class ImageField extends DataControlField
public class ImageField extends
 DataControlField
解説解説

データ バインド コントロール (GridView、DetailsView など) はこの ImageField クラス使用して表示されるレコードイメージ表示しますImageField オブジェクトは、そのオブジェクト使用しているデータ バインド コントロールにより異なった形式表示されます。たとえば、ImageField オブジェクトは、GridView コントロールでは列として表示されDetailsView コントロールでは行として表示されます。

イメージ表示するには、ImageField オブジェクトを、イメージURL格納されているデータ ソースフィールドバインドする必要があります。これは、DataImageUrlField プロパティ設定することによって行いますURL 値は DataImageUrlFormatString プロパティ使って書式設定できますイメージごとに、代替テキスト関連付けることもできますイメージ読み込むことができなかったり、イメージアクセスできなかった場合、このテキスト表示されます。ツール ヒント機能サポートしているブラウザ場合、このテキストツール ヒントとしても表示されます。表示されるイメージ代替テキスト指定するには、次のいずれか方法使用します

イメージURL 値が null 参照 (Visual Basic では Nothing) の場合イメージ表示されません。null 参照 (Visual Basic では Nothing) のフィールドに対して代替イメージ表示するには、NullImageUrl プロパティ設定します代替イメージではなく代替テキスト表示されるようにするには、NullDisplayText プロパティ設定します

既定では、宣言したすべてのフィールドデータ バインド コントロール表示されます。Visible プロパティfalse設定すると、データ バインド コントロールImageField オブジェクトを非表示できます

また、ImageField オブジェクトヘッダー セクションおよびフッター セクションカスタマイズできますヘッダーまたはフッター セクションキャプション表示するには、HeaderText または FooterText プロパティそれぞれ設定しますヘッダー セクションテキストではなくイメージ表示するには、HeaderImageUrl プロパティ設定します。ShowHeader プロパティfalse設定すると、ImageField オブジェクトヘッダー セクションを非表示できます

メモメモ

一部データ バインド コントロール (GridView コントロールなど) では、コントロールヘッダー セクションをすべて表示するか、すべて非表示にするかしかできません。これらのデータ バインド コントロールは、個々データ バインド フィールドShowHeader プロパティサポートしていません。データ バインド コントロールヘッダー セクション (存在する場合) 全体表示または非表示にするには、コントロールShowHeader プロパティ使用します

また、フィールド各部分にスタイル プロパティ設定すると、ImageField オブジェクト外観 (フォントの色や背景色など) をカスタマイズできますさまざまなスタイル プロパティの一覧を次の表に示します

使用例使用例

GridView コントロールImageField オブジェクト使用してイメージ表示する方法次の例に示します

<%@ Page language="VB" %>

<html>
  <body>
    <form 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="C#" %>

<html>
  <body>
    <form 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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.WebControls.DataControlField
    System.Web.UI.WebControls.ImageField
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ImageField メンバ
System.Web.UI.WebControls 名前空間
GridView クラス
GridView.Columns プロパティ
DetailsView クラス
DetailsView.Fields プロパティ
BoundField クラス
ButtonField クラス
CheckBoxField クラス
CommandField クラス
HyperLinkField クラス
TemplateField
AlternateText
DataAlternateTextField
DataAlternateTextFormatString
DataImageUrlField
DataImageUrlFormatString
NullDisplayText
NullImageUrl



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ImageField クラス」の関連用語

ImageField クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ImageField クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS