Share via


CommandField.ShowInsertButton プロパティ

定義

CommandField フィールドに New ボタンが表示されるかどうかを示す値を取得または設定します。

public:
 virtual property bool ShowInsertButton { bool get(); void set(bool value); };
public virtual bool ShowInsertButton { get; set; }
member this.ShowInsertButton : bool with get, set
Public Overridable Property ShowInsertButton As Boolean

プロパティ値

CommandField に New ボタンを表示する場合は true。それ以外の場合は false。 既定値は、false です。

次のコード例では、 プロパティを ShowInsertButton 使用してコントロールに DetailsView [新規] ボタンを表示する方法を示します。これにより、ユーザーは新しいレコードをデータ ソースに追加できます。


<%@ 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>CommandField Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>CommandField Example</h3>

      <asp:detailsview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneraterows="false"
        datakeynames="CustomerID"  
        allowpaging="true" 
        runat="server">
        
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="CompanyName"/>
          <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"/>
          <asp:commandfield showinsertbutton="true"
            showheader="true"
            headertext="Add Customer"/>
        </fields>
        
      </asp:detailsview>
            
      <!-- 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]"
        insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </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>CommandField Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>CommandField Example</h3>

      <asp:detailsview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneraterows="false"
        datakeynames="CustomerID"  
        allowpaging="true" 
        runat="server">
        
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="CompanyName"/>
          <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"/>
          <asp:commandfield showinsertbutton="true"
            showheader="true"
            headertext="Add Customer"/>
        </fields>
        
      </asp:detailsview>
            
      <!-- 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]"
        insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

注釈

フィールドに ShowInsertButton [新規] ボタンを表示するかどうかを指定するには、 プロパティを CommandField 使用します。 [新規] ボタンはフィールドに CommandField 1 回だけ表示され、ユーザーはデータ ソースに新しいレコードを追加できます。

注意

このプロパティは、コントロールなどの DetailsView 挿入操作をサポートするデータ バインド コントロールにのみ適用されます。

ユーザーが [新規] ボタンをクリックすると、データ バインド コントロールに表示されるフィールドごとに入力コントロールが表示され、ユーザーは新しいレコードの値を入力できます。 [新規] ボタンは [挿入] ボタンと [キャンセル] ボタンに置き換えられ、フィールド内の CommandField 他のすべてのコマンド ボタンは非表示になります。 [挿入] ボタンをクリックすると、データ ソースにレコードが追加されますが、[キャンセル] ボタンをクリックすると操作が取り消されます。

注意

データ バインド コントロールをデータ ソース コントロール (コントロールなど SqlDataSource ) と組み合わせて使用すると、データ バインド コントロールはデータ ソース コントロールの機能を利用し、自動挿入機能を提供できます。 他のデータ ソースの場合は、データ バインド コントロールの適切なイベント中に挿入操作を実行するルーチンを指定する必要があります。

フィールドの プロパティが ButtonType または ButtonType.LinkButtonType.Button設定されている場合は、 プロパティをNewText使用して、[新規] ボタンに表示するテキストを指定します。CommandField または、最初に プロパティを に設定してから、 プロパティButtonType.ImageButtonType設定して画像をNewImageUrl表示することもできます。

適用対象

こちらもご覧ください