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 プロパティ


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

  名前 説明
パブリック プロパティ Cancel  イベントキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。)
パブリック プロパティ CommandArgument FormView コントロール渡される挿入操作用のコマンド引数取得します
パブリック プロパティ Values 挿入するレコードフィールドの名前と値のペア格納しているディクショナリを取得します
参照参照

関連項目

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

FormViewInsertEventArgs メソッド


FormViewInsertEventArgs メンバ

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

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド FormViewInsertEventArgs FormViewInsertEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Cancel  イベントキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。)
パブリック プロパティ CommandArgument FormView コントロール渡される挿入操作用のコマンド引数取得します
パブリック プロパティ Values 挿入するレコードフィールドの名前と値のペア格納しているディクショナリを取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

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


このページでは「.NET Framework クラス ライブラリ リファレンス」からFormViewInsertEventArgsを検索した結果を表示しています。
Weblioに収録されているすべての辞書からFormViewInsertEventArgsを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFormViewInsertEventArgs を検索

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

辞書ショートカット

すべての辞書の索引

「FormViewInsertEventArgs」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS