FormView.ItemDeleting イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FormView.ItemDeleting イベントの意味・解説 

FormView.ItemDeleting イベント

メモ : このイベントは、.NET Framework version 2.0新しく追加されたものです。

FormView コントロール内の Delete ボタンクリックされた場合に、削除操作前に発生します

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

Public Event ItemDeleting As
 FormViewDeleteEventHandler
Dim instance As FormView
Dim handler As FormViewDeleteEventHandler

AddHandler instance.ItemDeleting, handler
public event FormViewDeleteEventHandler ItemDeleting
public:
event FormViewDeleteEventHandler^ ItemDeleting {
    void add (FormViewDeleteEventHandler^ value);
    void remove (FormViewDeleteEventHandler^ value);
}
/** @event */
public void add_ItemDeleting (FormViewDeleteEventHandler
 value)

/** @event */
public void remove_ItemDeleting (FormViewDeleteEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

ItemDeleting イベント使用して削除操作キャンセルする方法次の例に示します

<%@ Page language="VB" %>

<script runat="server">

  Sub EmployeeFormView_ItemDeleting(ByVal sender
 As Object, ByVal e As
 FormViewDeleteEventArgs)
  
    ' Get the employee ID, name, and job title from the Keys and Values
    ' properties.
    Dim keyValue As String
 = e.Keys("EmployeeID").ToString()
    Dim employeeName As String
 = e.Values("FirstName").ToString() & _
      " " & e.Values("LastName").ToString()
    Dim title As String
 = e.Values("Title").ToString()

    ' Cancel the delete operation if the user attempts to 
    ' delete a protected record. In this example, records for
    ' employees with a "Sales Manager" job title are protected.
    If Title.Equals("Sales Manager")
 Then
    
      e.Cancel = True
      MessageLabel.Text = "You cannot delete record "
 & _
        e.RowIndex.ToString() & ". " & employeeName
 & _
        " (Employee Number " & keyValue.ToString()
 & _
        ") is protected."
    
    End If

  End Sub
   
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>FormViewDeleteEventArgs Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        onitemdeleting="EmployeeFormView_ItemDeleting"
  
        runat="server">
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>'
 
                  runat="server"/>
              </td>
              <td>
                <asp:label id="FirstNameLabel"
                  text='<%#Bind("FirstName")%>'
                  font-bold="true"
                  runat="server"/>
                <asp:label id="LastNameLabel"
                  text='<%#Bind("LastName")%>'
                  font-bold="true"
                  runat="server"/>
                <br/>     
                <asp:label id="TitleLabel"
                  text='<%#Bind("Title")%>'
                  runat="server"/>        
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:button id="DeleteButton"
                  text="Delete Record"
                  commandname="Delete"
                  runat="server" />
              </td>
            </tr>
          </table>
        
        </itemtemplate>         
                  
      </asp:formview>
      
      <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]"
        deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

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

<script runat="server">

  void EmployeeFormView_ItemDeleting(Object sender, FormViewDeleteEventArgs
 e)
  {
    // Get the employee ID, name, and job title from the Keys and Values
    // properties.
    String keyValue = e.Keys["EmployeeID"].ToString();
    String employeeName = e.Values["FirstName"].ToString() +
      " " + e.Values["LastName"].ToString();
    String title = e.Values["Title"].ToString();

    // Cancel the delete operation if the user attempts to 
    // delete a protected record. In this example, records for
    // employees with a "Sales Manager" job title are protected.
    if (title.Equals("Sales Manager"))
    {
      e.Cancel = true;
      MessageLabel.Text = "You cannot delete record " +
        e.RowIndex.ToString() + ". " + employeeName +
        " (Employee Number " + keyValue.ToString() +
        ") is protected.";
    }

  }
   
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>FormViewDeleteEventArgs Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        onitemdeleting="EmployeeFormView_ItemDeleting"  
        runat="server">
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <asp:label id="FirstNameLabel"
                  text='<%#Bind("FirstName")%>'
                  font-bold="true"
                  runat="server"/>
                <asp:label id="LastNameLabel"
                  text='<%#Bind("LastName")%>'
                  font-bold="true"
                  runat="server"/>
                <br/>     
                <asp:label id="TitleLabel"
                  text='<%#Bind("Title")%>'
                  runat="server"/>        
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:button id="DeleteButton"
                  text="Delete Record"
                  commandname="Delete"
                  runat="server" />
              </td>
            </tr>
          </table>
        
        </itemtemplate>         
                  
      </asp:formview>
      
      <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]"
        deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FormView クラス
FormView メンバ
System.Web.UI.WebControls 名前空間
FormViewDeleteEventArgs
FormViewDeleteEventHandler
Cancel
RowIndex
Keys
Values
OnItemDeleting
その他の技術情報
イベント利用


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

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

辞書ショートカット

すべての辞書の索引

「FormView.ItemDeleting イベント」の関連用語

FormView.ItemDeleting イベントのお隣キーワード
検索ランキング

   

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



FormView.ItemDeleting イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS