LinqDataSource.Inserted Zdarzenie

Definicja

Występuje po zakończeniu operacji wstawiania.

public:
 event EventHandler<System::Web::UI::WebControls::LinqDataSourceStatusEventArgs ^> ^ Inserted;
public event EventHandler<System.Web.UI.WebControls.LinqDataSourceStatusEventArgs> Inserted;
member this.Inserted : EventHandler<System.Web.UI.WebControls.LinqDataSourceStatusEventArgs> 
Public Custom Event Inserted As EventHandler(Of LinqDataSourceStatusEventArgs) 

Typ zdarzenia

Przykłady

W poniższym przykładzie pokazano, jak utworzyć program obsługi zdarzeń dla Inserted zdarzenia, który sprawdza wyjątki i pobiera właściwość tożsamości dla nowego rekordu.

protected void LinqDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception == null)
    {
        Product newProduct = (Product)e.Result;
        Literal1.Text = "The new product id is " + newProduct.ProductID;
        Literal1.Visible = true;            
    }
    else
    {
        LogError(e.Exception.Message);
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified.";
        Literal1.Visible = true;
        e.ExceptionHandled = true;            
    }
}
Protected Sub LinqDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs)
    If (IsNothing(e.Exception)) Then
        Dim newProduct As Product
        newProduct = CType(e.Result, Product)
        Literal1.Text = "The new product id is " & newProduct.ProductID
        Literal1.Visible = True
    Else
        LogError(e.Exception.Message)
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified."
        Literal1.Visible = True
        e.ExceptionHandled = True
    End If
End Sub

Uwagi

Obsłuż zdarzenie, Inserted aby przechwycić wszelkie wyjątki od operacji wstawiania lub zbadać wartości po zakończeniu operacji wstawiania. Nowe wartości można pobrać za pośrednictwem LinqDataSourceStatusEventArgs obiektu, który jest przekazywany do procedur obsługi zdarzeń. Na przykład można użyć LinqDataSourceStatusEventArgs obiektu , aby pobrać właściwość tożsamości wygenerowaną przez bazę danych dla nowego rekordu danych.

Dotyczy