DetailsViewInsertedEventArgs DetailsViewInsertedEventArgs DetailsViewInsertedEventArgs DetailsViewInsertedEventArgs Class

定義

ItemInserted イベントのデータを提供します。Provides data for the ItemInserted event.

public ref class DetailsViewInsertedEventArgs : EventArgs
public class DetailsViewInsertedEventArgs : EventArgs
type DetailsViewInsertedEventArgs = class
    inherit EventArgs
Public Class DetailsViewInsertedEventArgs
Inherits EventArgs
継承
DetailsViewInsertedEventArgsDetailsViewInsertedEventArgsDetailsViewInsertedEventArgsDetailsViewInsertedEventArgs

次のコード例は、使用する方法を示します、DetailsViewInsertedEventArgsオブジェクトのイベント ハンドラーに渡される、ItemInserted挿入操作中に例外が発生したかどうかを決定するイベントです。The following code example demonstrates how to use the DetailsViewInsertedEventArgs object passed to the event handler for the ItemInserted event to determine whether an exception occurred during an insert operation.


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void CustomerDetailsView_ItemInserted(Object sender, 
    DetailsViewInsertedEventArgs e)
  {
    // Use the Exception property to determine whether an exception
    // occurred during the insert operation.
    if (e.Exception == null && e.AffectedRows == 1)
    {
      // Use the Values property to get the value entered by 
      // the user for the CompanyName field.
      String name = e.Values["CompanyName"].ToString();

      // Display a confirmation message.
      MessageLabel.Text = name + " added successfully. ";

    }
    else
    {
      // Insert the code to handle the exception.
      MessageLabel.Text = e.Exception.Message;
      
      // Use the ExceptionHandled property to indicate that the 
      // exception is already handled.
      e.ExceptionHandled = true;
      
      // When an exception occurs, keep the DetailsView
      // control in insert mode.
      e.KeepInInsertMode = true;
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewInsertedEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewInsertedEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateinsertbutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          oniteminserted="CustomerDetailsView_ItemInserted" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <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]"
          insertcommand="INSERT INTO [Customers]([CustomerID], 
            [CompanyName], [Address], [City], [PostalCode], 
            [Country]) VALUES (@CustomerID, @CompanyName, @Address, 
            @City, @PostalCode, @Country)"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>


<%@ Page language="VB" autoeventwireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub CustomerDetailsView_ItemInserted(ByVal sender As Object, _
    ByVal e As DetailsViewInsertedEventArgs) _
    Handles CustomerDetailsView.ItemInserted

    ' Use the Exception property to determine whether an exception
    ' occurred during the insert operation.
    If e.Exception Is Nothing And e.AffectedRows = 1 Then
    
      ' Use the Values property to get the value entered by 
      ' the user for the CompanyName field.
      Dim name As String = e.Values("CompanyName").ToString()

      ' Display a confirmation message.
      MessageLabel.Text = name & " added successfully. "
    
    Else
    
      ' Insert the code to handle the exception.
      MessageLabel.Text = e.Exception.Message
      
      ' Use the ExceptionHandled property to indicate that the 
      ' exception is already handled.
      e.ExceptionHandled = True
      
      ' When an exception occurs, keep the DetailsView
      ' control in insert mode.
      e.KeepInInsertMode = True
    
    End If
        
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewInsertedEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewInsertedEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateinsertbutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <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]"
          insertcommand="INSERT INTO [Customers]([CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

注釈

DetailsView生成を制御、ItemInsertedときの Insert ボタンにイベント (ボタンをそのCommandNameプロパティが"Insert"に設定) コントロール内でをクリックした後は、DetailsViewコントロールは、レコードを挿入します。The DetailsView control raises the ItemInserted event when an Insert button (a button with its CommandName property set to "Insert") within the control is clicked, but after the DetailsView control inserts the record. これにより、このイベントが発生するたびに、挿入操作の結果を確認してなどのカスタムのルーチンを実行するイベント ハンドラーを提供できます。This allows you to provide an event handler that performs a custom routine, such as checking the results of an insert operation, whenever this event occurs.

ADetailsViewInsertedEventArgsと発生した例外の影響を受けたレコードの数を決定することができます、イベント ハンドラーに渡されるオブジェクト。A DetailsViewInsertedEventArgs object is passed to the event handler, which allows you to determine the number of records affected and any exceptions that might have occurred. 挿入操作によって影響を受けたレコードの数を調べるには、AffectedRowsプロパティ。To determine the number of records affected by the insert operation, use the AffectedRows property. 使用して、Exceptionプロパティを任意の例外が発生したかどうかを判断します。Use the Exception property to determine whether any exceptions occurred. かどうか、例外によって処理されたイベント ハンドラーの設定を指定することも、ExceptionHandledプロパティ。You can also indicate whether the exception was handled in the event handler by setting the ExceptionHandled property. 挿入されたレコードの値にアクセスする必要がある場合、Valuesプロパティ。If you need to access the values of the inserted record, use the Values property.

既定で、DetailsViewコントロールで指定されたモードに戻る、DefaultMode挿入操作の後のプロパティ。By default, the DetailsView control returns to the mode specified by the DefaultMode property after an insert operation. 保持する、DetailsView挿入モードでコントロールを設定、KeepInInsertModeプロパティをtrueします。To keep the DetailsView control in insert mode, set the KeepInInsertMode property to true.

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。For more information about how to handle events, see Handling and Raising Events.

DetailsViewDeletedEventArgs クラスのインスタンスの初期プロパティ値一覧については、DetailsViewDeletedEventArgs コンストラクターに関するトピックを参照してください。For a list of initial property values for an instance of the DetailsViewDeletedEventArgs class, see the DetailsViewDeletedEventArgs constructor.

コンストラクター

DetailsViewInsertedEventArgs(Int32, Exception) DetailsViewInsertedEventArgs(Int32, Exception) DetailsViewInsertedEventArgs(Int32, Exception) DetailsViewInsertedEventArgs(Int32, Exception)

DetailsViewInsertedEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the DetailsViewInsertedEventArgs class.

プロパティ

AffectedRows AffectedRows AffectedRows AffectedRows

挿入操作の影響を受けた行の数を取得します。Gets the number of rows affected by the insert operation.

Exception Exception Exception Exception

挿入操作中に例外が発生した場合は、その例外を取得します。Gets the exception (if any) that was raised during the insert operation.

ExceptionHandled ExceptionHandled ExceptionHandled ExceptionHandled

挿入操作中に発生した例外がイベント ハンドラーで処理されたかどうかを示す値を取得または設定します。Gets or sets a value indicating whether an exception that was raised during the insert operation was handled in the event handler.

KeepInInsertMode KeepInInsertMode KeepInInsertMode KeepInInsertMode

挿入操作の後で、DetailsView コントロールを挿入モードのまま維持するかどうかを示す値を取得または設定します。Gets or sets a value indicating whether the DetailsView control should remain in insert mode after an insert operation.

Values Values Values Values

挿入されたレコードのフィールドの名前と値のペアを格納しているディクショナリを取得します。Gets a dictionary that contains the field name/value pairs for the inserted record.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください