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

CommandField クラス

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

データ バインド コントロール選択編集挿入、または削除の各操作実行するコマンド ボタン表示する特殊なフィールド表します

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

Public Class CommandField
    Inherits ButtonFieldBase
public class CommandField : ButtonFieldBase
public ref class CommandField : public
 ButtonFieldBase
public class CommandField extends ButtonFieldBase
public class CommandField extends
 ButtonFieldBase
解説解説

CommandField クラスは、データ バインド コントロール (GridView および DetailsView など) で使用される特殊なフィールドで、削除編集挿入、または選択の各操作実行するコマンド ボタン表示します。これらの操作実行するコマンド ボタンは、次の表に示すプロパティ使用して表示または非表示できます

プロパティ

説明

ShowDeleteButton

データ バインド コントロール内のレコードごとに、CommandField フィールドDelete ボタン表示または非表示にします。Delete ボタン使用すると、ユーザーデータ ソースからレコード削除できます

ShowEditButton

データ バインド コントロール内のレコードごとに、CommandField フィールドEdit ボタン表示または非表示にします。Edit ボタン使用すると、ユーザーデータ ソースレコード編集できますユーザー特定のレコードEdit ボタンクリックすると、Edit ボタンUpdate ボタンCancel ボタンに置き換わりますその他のコマンド ボタンもすべて非表示なります

ShowInsertButton

CommandField フィールドNew ボタン表示または非表示にします。New ボタン使用すると、ユーザーデータ ソース新しレコード挿入できますユーザーNew ボタンクリックすると、Insert ボタンCancel ボタンに置き換わりますその他のコマンド ボタンもすべて非表示なります

ShowSelectButton

データ バインド コントロール内のレコードごとに、CommandField フィールドSelect ボタン表示または非表示にします。Select ボタン使用すると、ユーザーデータ バインド コントロール内のレコード選択できます

また、ShowCancelButton プロパティ設定することにより、レコード編集モードまたは挿入モードのときに表示される Cancel ボタン表示または非表示にすることもできます

CommandField フィールドは、それが使用されているデータ バインド コントロールによって表示異なります。たとえば、CommandField フィールドは、GridView コントロールでは列として表示されDetailsView コントロールでは行として表示されます。

表示するボタンの種類指定するには、ButtonType プロパティ使用しますButtonType プロパティButtonType.Button または ButtonType.Link設定されている場合次の表に示すプロパティ設定してボタン表示するテキスト指定できます

コマンド ボタンまたはリンク ボタン表示する代わりにButtonType プロパティButtonType.Image設定し次の表に示すプロパティ設定してイメージ ボタン表示できます

既定では、ユーザーCommandField フィールドボタンクリックすると、ページすべての検証コントロール検証実行されます。ボタンクリックしたときに検証が行われないようにするには、CausesValidation プロパティfalse設定します

Visible プロパティfalse設定すると、データ バインド コントロールCommandField フィールドを非表示できます

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

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

使用例使用例

CommandField フィールド使用してコントロール表示しGridView コントロール内のレコード編集する方法次のコード例示します

<%@ Page language="VB" %>

<html>
  <body>
    <form runat="server">
      
      <h3>CommandField Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showeditbutton="true"
            headertext="Edit Controls"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </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="CustomersSqlDataSource"
  
        selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update Customers Set CompanyName=@CompanyName,
 Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID
 = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<html>
  <body>
    <form runat="server">
      
      <h3>CommandField Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showeditbutton="true"
            headertext="Edit Controls"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address,
 City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

CancelTextEditText、および UpdateText の各プロパティ使用して編集コントロールテキストカスタマイズする方法次のコード例示します

<%@ Page language="VB" %>

<html>
  <body>
    <form runat="server">
      
      <h3>CommandField Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showeditbutton="true"
            edittext="Edit Customer"
            canceltext="Discard"
            updatetext="Revise"
            headertext="Edit Controls"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </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="CustomersSqlDataSource"
  
        selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update Customers Set CompanyName=@CompanyName,
 Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID
 = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<html>
  <body>
    <form runat="server">
      
      <h3>CommandField Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showeditbutton="true"
            edittext="Edit Customer"
            canceltext="Discard"
            updatetext="Revise"
            headertext="Edit Controls"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address,
 City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.WebControls.DataControlField
     System.Web.UI.WebControls.ButtonFieldBase
      System.Web.UI.WebControls.CommandField
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CommandField メンバ
System.Web.UI.WebControls 名前空間
GridView
Columns
DetailsView
Fields
BoundField クラス
ButtonField クラス
ButtonFieldBase クラス
CheckBoxField クラス
DataControlField
HyperLinkField
TemplateField
ButtonFieldBase.ButtonType プロパティ
CancelText
DeleteImageUrl
DeleteText
EditImageUrl
EditText
InsertImageUrl
InsertText
NewImageUrl
NewText
SelectImageUrl
SelectText
ShowCancelButton
ShowDeleteButton
ShowEditButton
ShowInsertButton
ShowSelectButton
UpdateImageUrl
UpdateText
ControlStyle
FooterStyle
HeaderStyle
ItemStyle



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

辞書ショートカット

すべての辞書の索引

「CommandField クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS