Breyta

Deila með


LinqDataSourceInsertEventArgs Class

Definition

Provides data for the Inserting event.

public ref class LinqDataSourceInsertEventArgs : System::ComponentModel::CancelEventArgs
public class LinqDataSourceInsertEventArgs : System.ComponentModel.CancelEventArgs
type LinqDataSourceInsertEventArgs = class
    inherit CancelEventArgs
Public Class LinqDataSourceInsertEventArgs
Inherits CancelEventArgs
Inheritance
LinqDataSourceInsertEventArgs

Examples

The following example shows a handler for the Inserting event. The object from the NewObject property is cast to a type named Product. The DateModified property of the Product object is set to the current date and time.

protected void LinqDataSource_Inserting(object sender, LinqDataSourceInsertEventArgs e)
{
    Product product = (Product)e.NewObject;
    product.DateModified = DateTime.Now;
}
Protected Sub LinqDataSource_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs)
    Dim product As Product
    product = CType(e.NewObject, Product)
    product.DateModified = DateTime.Now
End Sub

The following example shows an event handler for the Inserting event. It displays any validation exception messages by using a Label control.

Protected Sub LinqDataSource_Inserting(ByVal sender As Object, _  
        ByVal e As LinqDataSourceInsertEventArgs)  
    If (e.Exception IsNot Nothing) Then  
        For Each innerException As KeyValuePair(Of String, Exception) _  
               In e.Exception.InnerExceptions  
            Label1.Text &= innerException.Key & ": " & _  
                innerException.Value.Message + "<br />"  
        Next  
        e.ExceptionHandled = True  
    End If  
End Sub  
protected void LinqDataSource_Inserting(object sender,   
        LinqDataSourceInsertEventArgs e)  
{  
    if (e.Exception != null)  
    {  
        foreach (KeyValuePair<string, Exception> innerException in   
             e.Exception.InnerExceptions)  
        {  
        Label1.Text += innerException.Key + ": " +   
            innerException.Value.Message + "<br />";  
        }  
        e.ExceptionHandled = true;  
    }  
}  

Remarks

The LinqDataSourceInsertEventArgs object is passed to any event handler for the Inserting event. The NewObject property contains the data that will be inserted.

You can use the LinqDataSourceInsertEventArgs object to examine the data before the insert operation is executed in the data source. You can then validate the data, examine validation errors from the data class, or change a value before the update. You can also cancel the insert operation.

If the object that represents the data source throws a validation exception before it inserts the data, the Exception property contains an instance of the LinqDataSourceValidationException class. You can retrieve all the validation exceptions through the InnerExceptions property. If no validation exception is thrown, the Exception property contains null. If you handle the validation exceptions and do not want the exception to be re-thrown, set the ExceptionHandled property to true.

Constructors

LinqDataSourceInsertEventArgs(LinqDataSourceValidationException)

Initializes a new instance of the LinqDataSourceInsertEventArgs class and specifies the provided exception.

LinqDataSourceInsertEventArgs(Object)

Initializes a new instance of the LinqDataSourceInsertEventArgs class.

Properties

Cancel

Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
Exception

Gets the exception that was thrown while the data was being validated before the insert operation.

ExceptionHandled

Gets or sets a value that indicates whether the exception was handled and that it should not be thrown again.

NewObject

Gets the object that contains the data to insert.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to