FormViewInsertEventArgsとは? わかりやすく解説

FormViewInsertEventArgs クラス

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

ItemInserting イベントのデータを提供します。

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

Public Class FormViewInsertEventArgs
    Inherits CancelEventArgs
Dim instance As FormViewInsertEventArgs
public class FormViewInsertEventArgs : CancelEventArgs
public ref class FormViewInsertEventArgs :
 public CancelEventArgs
public class FormViewInsertEventArgs extends
 CancelEventArgs
public class FormViewInsertEventArgs extends
 CancelEventArgs
解説解説

FormView コントロールは、コントロール内の Insert ボタン (CommandName プロパティが "Insert" に設定されたボタン) がクリックされた場合に、FormView コントロールが実際にレコードを挿入する前に ItemInserting イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (データ ソースに挿入する前にレコードの値の HTML エンコーディングや検証を行うなど) を実行するイベント処理メソッドを提供できます。

FormViewInsertEventArgs オブジェクトがイベント処理メソッドに渡されることにより、FormView コントロールに送信される省略可能なコマンド引数の値を確認したり、挿入操作をキャンセルする必要があることを示したりできます。コマンド引数の値を確認するには、CommandArgument プロパティを使用します。挿入操作をキャンセルするには、Cancel プロパティを true に設定します。また、Values プロパティを使用して、新規レコードのフィールド値を読み込んだり、変更したりすることもできます。

イベント処理の詳細については、「イベントの利用」を参照してください。

FormViewInsertEventArgs クラスのインスタンスの初期プロパティ値の一覧については、FormViewInsertEventArgs コンストラクタのトピックを参照してください。

使用例使用例

ItemInserting イベントのイベント処理メソッドに渡された FormViewInsertEventArgs オブジェクトを使用して、ユーザーがフィールドに何も入力していない場合に挿入操作をキャンセルする方法を次の例に示します。

<%@ Page language="VB" %>

<script runat="server">

  Sub EmployeeFormView_ItemInserting(ByVal
 sender As Object, ByVal
 e As FormViewInsertEventArgs)

    MessageLabel.Text = ""

    ' Iterate through the items in the Values collection
    ' and verify that the user entered a value for each 
    ' text box displayed in the insert item template. Cancel
    ' the insert operation if the user left a text box empty.
    
    ' In Visual Basic, the DictionaryItem objects contained in 
    ' the Values collection must be copied to an array before
    ' you can iterate through the collection.
    Dim itemArray(e.Values.Count - 1) As DictionaryEntry
    e.Values.CopyTo(itemArray, 0)
    
    Dim entry As DictionaryEntry
    For Each entry In itemArray
    
      If entry.Value.Equals("")
 Then
      
        ' Use the Cancel property to cancel the 
        ' insert operation.
        e.Cancel = True

        MessageLabel.Text &= "Please enter a value for the
 " & _
          entry.Key.ToString() & " field.<br/>"
      
      End If
      
    Next
    
  End Sub

  Sub EmployeeFormView_ModeChanged(ByVal sender
 As Object, ByVal e As
 EventArgs)
  
    ' Clear the MessageLabel Label control when the FormView
    ' control changes modes.
    MessageLabel.Text = ""
  
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>FormViewInsertEventArgs Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        emptydatatext="No employees found."
        oniteminserting="EmployeeFormView_ItemInserting"
        onmodechanged="EmployeeFormView_ModeChanged"
        runat="server">

        <itemtemplate>
          <table>
            <tr>
              <td rowspan="5">
                <asp:image id="CompanyLogoImage"
                  imageurl="~/Images/Logo.jpg"
                  alternatetext="Company Logo"
                  runat="server"/>
              </td>
              <td colspan="2">
                  &nbsp; 
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <%# Eval("FirstName") %> <%#
 Eval("LastName") %>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <%# Eval("Title") %>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="NewButton"
                  text="New"
                  commandname="New"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </itemtemplate>
        <insertitemtemplate>
          <table>
            <tr>
              <td rowspan="4">
                <asp:image id="CompanyLogoEditImage"
                  imageurl="~/Images/Logo.jpg"
                  alternatetext="Company Logo"
                  runat="server"/>
              </td>
              <td colspan="2">
                  &nbsp; 
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <asp:textbox id="FirstNameInsertTextBox"
                  text='<%# Bind("FirstName") %>'
                  runat="server"/>
                <asp:textbox id="LastNameInsertTextBox"
                  text='<%# Bind("LastName") %>'
                  runat="server"/>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <asp:textbox id="TitleInsertTextBox"
                  text='<%# Bind("Title") %>'
                  runat="server"/> 
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="InsertButton"
                  text="Insert"
                  commandname="Insert"
                  runat="server"/>
                <asp:linkbutton id="CancelButton"
                  text="Cancel"
                  commandname="Cancel"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </insertitemtemplate> 
                  
      </asp:formview>
      
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>

      <!-- 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],
 [Title], [PhotoPath] From [Employees]"
        insertcommand="Insert Into [Employees] ([LastName], [FirstName],
 [Title]) VALUES (@LastName, @FirstName, @Title)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

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

<script runat="server">

  void EmployeeFormView_ItemInserting(Object sender, FormViewInsertEventArgs
 e)
  {

    MessageLabel.Text = "";

    // Iterate through the items in the Values collection
    // and verify that the user entered a value for each 
    // text box displayed in the insert item template. Cancel
    // the insert operation if the user left a text box empty.
    foreach (DictionaryEntry entry in e.Values)
    {
      if (entry.Value.Equals(""))
      {
        // Use the Cancel property to cancel the 
        // insert operation.
        e.Cancel = true;

        MessageLabel.Text += "Please enter a value for the
 " +
          entry.Key.ToString() + " field.<br/>";

      }
    }
  }

  void EmployeeFormView_ModeChanged(Object sender, EventArgs e)
  {
    // Clear the MessageLabel Label control when the FormView
    // control changes modes.
    MessageLabel.Text = "";
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>FormViewInsertEventArgs Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        emptydatatext="No employees found."
        oniteminserting="EmployeeFormView_ItemInserting"
        onmodechanged="EmployeeFormView_ModeChanged"
        runat="server">

        <itemtemplate>
          <table>
            <tr>
              <td rowspan="5">
                <asp:image id="CompanyLogoImage"
                  imageurl="~/Images/Logo.jpg"
                  alternatetext="Company Logo"
                  runat="server"/>
              </td>
              <td colspan="2">
                  &nbsp; 
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <%# Eval("FirstName") %> <%# Eval("LastName")
 %>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <%# Eval("Title") %>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="NewButton"
                  text="New"
                  commandname="New"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </itemtemplate>
        <insertitemtemplate>
          <table>
            <tr>
              <td rowspan="4">
                <asp:image id="CompanyLogoEditImage"
                  imageurl="~/Images/Logo.jpg"
                  alternatetext="Company Logo"
                  runat="server"/>
              </td>
              <td colspan="2">
                  &nbsp; 
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <asp:textbox id="FirstNameInsertTextBox"
                  text='<%# Bind("FirstName") %>'
                  runat="server"/>
                <asp:textbox id="LastNameInsertTextBox"
                  text='<%# Bind("LastName") %>'
                  runat="server"/>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <asp:textbox id="TitleInsertTextBox"
                  text='<%# Bind("Title") %>'
                  runat="server"/> 
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="InsertButton"
                  text="Insert"
                  commandname="Insert"
                  runat="server"/>
                <asp:linkbutton id="CancelButton"
                  text="Cancel"
                  commandname="Cancel"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </insertitemtemplate> 
                  
      </asp:formview>
      
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>

      <!-- 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], [Title],
 [PhotoPath] From [Employees]"
        insertcommand="Insert Into [Employees] ([LastName], [FirstName], [Title])
 VALUES (@LastName, @FirstName, @Title)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
     System.ComponentModel.CancelEventArgs
      System.Web.UI.WebControls.FormViewInsertEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FormViewInsertEventArgs メンバ
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewInsertEventHandler
CancelEventArgs
FormView.ItemInserting イベント
Cancel
CommandArgument
Values

FormViewInsertEventArgs コンストラクタ

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

FormViewInsertEventArgs クラスの新しいインスタンスを初期化します。

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

Public Sub New ( _
    commandArgument As Object _
)
Dim commandArgument As Object

Dim instance As New FormViewInsertEventArgs(commandArgument)
public FormViewInsertEventArgs (
    Object commandArgument
)
public:
FormViewInsertEventArgs (
    Object^ commandArgument
)
public FormViewInsertEventArgs (
    Object commandArgument
)
public function FormViewInsertEventArgs (
    commandArgument : Object
)

パラメータ

commandArgument

FormView コントロールに渡される省略可能なコマンド引数。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FormViewInsertEventArgs クラス
FormViewInsertEventArgs メンバ
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewInsertEventHandler
FormView.ItemInserting イベント
CommandArgument

FormViewInsertEventArgs プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

FormViewInsertEventArgs クラス
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewInsertEventHandler
CancelEventArgs
FormView.ItemInserting イベント
Cancel
CommandArgument
Values

FormViewInsertEventArgs メソッド


FormViewInsertEventArgs メンバ

ItemInserting イベントのデータを提供します。

FormViewInsertEventArgs データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド FormViewInsertEventArgs FormViewInsertEventArgs クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

FormViewInsertEventArgs クラス
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewInsertEventHandler
CancelEventArgs
FormView.ItemInserting イベント
Cancel
CommandArgument
Values



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「FormViewInsertEventArgs」の関連用語

FormViewInsertEventArgsのお隣キーワード
検索ランキング

   

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



FormViewInsertEventArgsのページの著作権

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

©2026 GRAS Group, Inc.RSS