DetailsViewInsertedEventArgs Sınıf

Tanım

ItemInserted olayı için veriler sağlar.

public ref class DetailsViewInsertedEventArgs : EventArgs
public class DetailsViewInsertedEventArgs : EventArgs
type DetailsViewInsertedEventArgs = class
    inherit EventArgs
Public Class DetailsViewInsertedEventArgs
Inherits EventArgs
Devralma
DetailsViewInsertedEventArgs

Örnekler

Aşağıdaki kod örneği, ekleme işlemi sırasında bir özel durumun oluşup oluşmadığını belirlemek üzere olay işleyicisine geçirilen nesnenin ItemInserted nasıl kullanılacağını DetailsViewInsertedEventArgs gösterir.


<%@ 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>

Açıklamalar

Denetim içindeki DetailsView bir Ekle düğmesine (özelliği "Ekle" olarak ayarlanmış bir düğmeCommandName) tıklandığında, ancak denetim kaydı ekledikten sonra DetailsView olayı tetiklerItemInserted. Bu, bu olay her gerçekleştiğinde bir ekleme işleminin sonuçlarını denetleme gibi özel bir yordam gerçekleştiren bir olay işleyicisi sağlamanıza olanak tanır.

DetailsViewInsertedEventArgs Olay işleyicisine, etkilenen kayıt sayısını ve oluşmuş olabilecek özel durumları belirlemenize olanak tanıyan bir nesne geçirilir. Ekleme işleminden etkilenen kayıt sayısını belirlemek için özelliğini kullanın AffectedRows . Exception Herhangi bir özel durumun oluşup oluşmadığını belirlemek için özelliğini kullanın. Özelliğini ayarlayarak özel durumun olay işleyicisinde işlenip işlenmediğini ExceptionHandled de belirtebilirsiniz. Eklenen kaydın değerlerine erişmeniz gerekiyorsa özelliğini kullanın Values .

Varsayılan olarak, DetailsView denetim ekleme işleminden sonra özelliği tarafından DefaultMode belirtilen moda döner. Denetimi ekleme modunda tutmak DetailsView için özelliğini olarak trueayarlayınKeepInInsertMode.

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Sınıfının bir örneğinin ilk özellik değerlerinin DetailsViewDeletedEventArgs listesi için oluşturucuya DetailsViewDeletedEventArgs bakın.

Oluşturucular

DetailsViewInsertedEventArgs(Int32, Exception)

DetailsViewInsertedEventArgs sınıfının yeni bir örneğini başlatır.

Özellikler

AffectedRows

Ekleme işleminden etkilenen satır sayısını alır.

Exception

Ekleme işlemi sırasında oluşturulan özel durumu (varsa) alır.

ExceptionHandled

Ekleme işlemi sırasında oluşturulan bir özel durumun olay işleyicisinde işlenip işlenmediğini belirten bir değer alır veya ayarlar.

KeepInInsertMode

Bir ekleme işleminden sonra denetimin DetailsView ekleme modunda kalıp kalmayacağını belirten bir değer alır veya ayarlar.

Values

Eklenen kayıt için alan adı/değer çiftlerini içeren bir sözlük alır.

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.