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

DetailsViewUpdateEventArgs クラス

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

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

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

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

DetailsView コントロールは、コントロール内の Update ボタン (CommandName プロパティが "Update" に設定されたボタン) がクリックされた場合に、DetailsView コントロールが実際にレコードを更新する前に ItemUpdating イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (データ ソースでレコードを更新する前にレコードの値を HTML エンコーディングするなど) を実行するイベント ハンドラを提供できます。

DetailsViewUpdateEventArgs オブジェクトがイベント ハンドラに渡されることにより、DetailsView コントロールに送信される省略可能なコマンド引数の値を確認したり、更新操作をキャンセルする必要があるかどうかを示したりできます。コマンド引数の値を確認するには、CommandArgument プロパティを使用します。更新操作をキャンセルするには、Cancel プロパティを true に設定します。また、Keys プロパティおよび NewValues プロパティを使用して、ユーザーが入力した新しい値を読み込んだり、変更したりすることもできます。Keys プロパティにはキー フィールドが格納され、NewValues プロパティにはキー以外のフィールドが格納されます。元のキー フィールド以外の値にアクセスする必要がある場合は、OldValues プロパティを使用します。

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

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

使用例使用例

ItemUpdating イベントのイベント ハンドラに渡された DetailsViewUpdateEventArgs オブジェクトを使用して、ユーザーが入力した値を検証する方法のコード例を次に示します。

<%@ Page language="VB" %>

<script runat="server">
  
  Sub CustomerDetailsView_ItemUpdating(ByVal
 sender As Object, _
    ByVal e As DetailsViewUpdateEventArgs)

    ' Validate the field values entered by the user. This
    ' example determines whether the user left any fields
    ' empty. Use the NewValues property to access the new 
    ' values entered by the user.
    Dim emptyFieldList As ArrayList = _
      ValidateFields(CType(e.NewValues, IOrderedDictionary))

    If emptyFieldList.Count > 0 Then

      ' The user left some fields empty. Display an error message.
      
      ' Use the Keys property to retrieve the key field value.
      Dim keyValue As String
 = e.Keys("CustomerID").ToString()

      MessageLabel.Text = _
        "You must enter a value for all fields of record "
 & _
        keyValue & ".<br/>The following fields are missing:<br/><br/>"

      ' Display the missing fields.
      Dim value As String
      For Each value In
 emptyFieldList
      
        ' Use the OldValues property access the original value
        ' of a field.
        MessageLabel.Text &= value & " - Original Value
 = " & _
          e.OldValues(value).ToString() & "<br>"
        
      Next

      ' Cancel the update operation.
      e.Cancel = True

    Else
    
      ' The field values passed validation. Clear the
      ' error message label.
      MessageLabel.Text = ""
      
    End If

  End Sub

    Function ValidateFields(ByVal list As
 IOrderedDictionary) _
      As ArrayList
    
        ' Create an ArrayList object to store the
        ' names of any empty fields.
        Dim emptyFieldList As New
 ArrayList()

        ' Iterate though the field values entered by
        ' the user and check for an empty field. Empty
        ' fields contain a null value.
        Dim entry As DictionaryEntry
    
        For Each entry In
 list
    
            If entry.Value Is Nothing
 Then
      
                ' Add the field name to the ArrayList object.
                emptyFieldList.Add(entry.Key.ToString())
        
            End If
        Next

        Return emptyFieldList
  
    End Function

  Sub CustomerDetailsView_ModeChanging(ByVal
 sender As Object, ByVal
 e As DetailsViewModeEventArgs)
  
    If e.CancelingEdit Then
      
      ' The user canceled the update operation.
      ' Clear the error message label.
      MessageLabel.Text = ""
    
    End If
    
  End Sub

</script>

<html>

  <body>
    <form runat="server">
        
      <h3>DetailsViewUpdateEventArgs Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogenerateeditbutton="true"  
          allowpaging="true"
          datakeynames="CustomerID" 
          onitemupdating="CustomerDetailsView_ItemUpdating"
          onmodechanging="CustomerDetailsView_ModeChanging"
 
          runat="server">
            
          <pagersettings position="Bottom"/>
 
                    
        </asp:detailsview>
        
        <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="DetailsViewSource"
          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"/>
            
      </form>
  </body>
</html>

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

<script runat="server">
  
    void CustomerDetailsView_ItemUpdating(Object sender, 
      DetailsViewUpdateEventArgs e)
    {

        // Validate the field values entered by the user. This
        // example determines whether the user left any fields
        // empty. Use the NewValues property to access the new 
        // values entered by the user.
        ArrayList emptyFieldList = 
          ValidateFields((IOrderedDictionary)e.NewValues);

        if (emptyFieldList.Count > 0)
        {

            // The user left some fields empty. 
            // Display an error message.

            // Use the Keys property to retrieve the key field value.
            String keyValue = e.Keys["CustomerID"].ToString();

            MessageLabel.Text = 
              "You must enter a value for all fields of record
 " +
              keyValue + ".<br/>The following fields are missing:<br/><br/>";

            // Display the missing fields.
            foreach (String value in emptyFieldList)
            {
                // Use the OldValues property access the original
                // value of a field.
                MessageLabel.Text += value + " - Original Value = " +
                  e.OldValues[value].ToString() + "<br>";
            }

            // Cancel the update operation.
            e.Cancel = true;

        }
        else
        {
            // The field values passed validation. Clear the
            // error message label.
            MessageLabel.Text = "";
        }

    }

    ArrayList ValidateFields(IOrderedDictionary list)
    {

        // Create an ArrayList object to store the
        // names of any empty fields.
        ArrayList emptyFieldList = new ArrayList();

        // Iterate though the field values entered by
        // the user and check for an empty field. Empty
        // fields contain a null value.
        foreach (DictionaryEntry entry in list)
        {
            if (entry.Value == null)
            {
                // Add the field name to the ArrayList object.
                emptyFieldList.Add(entry.Key.ToString());
            }
        }

        return emptyFieldList;
    }

    void CustomerDetailsView_ModeChanging(Object sender, 
      DetailsViewModeEventArgs e)
    {
        if (e.CancelingEdit)
        {
            // The user canceled the update operation.
            // Clear the error message label.
            MessageLabel.Text = "";
        }
    }

</script>

<html>

  <body>
    <form runat="server">
        
      <h3>DetailsViewUpdateEventArgs Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogenerateeditbutton="true"  
          allowpaging="true"
          datakeynames="CustomerID" 
          onitemupdating="CustomerDetailsView_ItemUpdating"
          onmodechanging="CustomerDetailsView_ModeChanging" 
          runat="server">
            
          <pagersettings position="Bottom"/> 
                    
        </asp:detailsview>
        
        <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="DetailsViewSource"
          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"/>
            
      </form>
  </body>
</html>

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

DetailsViewUpdateEventArgs コンストラクタ

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

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

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

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

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

パラメータ

commandArgument

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

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

DetailsViewUpdateEventArgs プロパティ


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

  名前 説明
パブリック プロパティ Cancel  イベントをキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。)
パブリック プロパティ CommandArgument DetailsView コントロールに渡される、更新処理のコマンド引数を取得します。
パブリック プロパティ Keys 更新するレコードのキー フィールドの名前/値ペアを格納しているディクショナリを取得します。
パブリック プロパティ NewValues 更新するレコードの新しいフィールドの名前/値ペアを格納しているディクショナリを取得します。
パブリック プロパティ OldValues 更新するレコードの元のフィールドの名前/値ペアを格納しているディクショナリを取得します。
参照参照

関連項目

DetailsViewUpdateEventArgs クラス
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewUpdateEventHandler
CancelEventArgs
DetailsView.ItemUpdating イベント
Cancel
CommandArgument
Keys
NewValues
OldValues
OnItemUpdating

DetailsViewUpdateEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DetailsViewUpdateEventArgs クラス
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewUpdateEventHandler
CancelEventArgs
DetailsView.ItemUpdating イベント
Cancel
CommandArgument
Keys
NewValues
OldValues
OnItemUpdating

DetailsViewUpdateEventArgs メンバ

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

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DetailsViewUpdateEventArgs DetailsViewUpdateEventArgs クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Cancel  イベントをキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。)
パブリック プロパティ CommandArgument DetailsView コントロールに渡される、更新処理のコマンド引数を取得します。
パブリック プロパティ Keys 更新するレコードのキー フィールドの名前/値ペアを格納しているディクショナリを取得します。
パブリック プロパティ NewValues 更新するレコードの新しいフィールドの名前/値ペアを格納しているディクショナリを取得します。
パブリック プロパティ OldValues 更新するレコードの元のフィールドの名前/値ペアを格納しているディクショナリを取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DetailsViewUpdateEventArgs クラス
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewUpdateEventHandler
CancelEventArgs
DetailsView.ItemUpdating イベント
Cancel
CommandArgument
Keys
NewValues
OldValues
OnItemUpdating



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「DetailsViewUpdateEventArgs」の関連用語

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

   

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



DetailsViewUpdateEventArgsのページの著作権

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

©2026 GRAS Group, Inc.RSS