Breyta

Deila með


LinqDataSourceStatusEventArgs Class

Definition

Provides data for the ContextCreated, Deleted, Inserted, Selected, and Updated events.

public ref class LinqDataSourceStatusEventArgs : EventArgs
public class LinqDataSourceStatusEventArgs : EventArgs
type LinqDataSourceStatusEventArgs = class
    inherit EventArgs
Public Class LinqDataSourceStatusEventArgs
Inherits EventArgs
Inheritance
LinqDataSourceStatusEventArgs

Examples

The following example shows an event handler for the Inserted event. In the event handler, if the Exception property is null, the product ID is retrieved from the object in the Result property. The product ID is a primary key for the table and is set by the database, therefore the value is not known until the insert operation has finished. The exception message is logged if the Exception property is not equal to null. The ExceptionHandled property is then set to true.

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

Remarks

The LinqDataSourceStatusEventArgs class enables you to examine the results of data operations that have been performed by a LinqDataSource control. A LinqDataSourceStatusEventArgs object is passed to event handlers for the ContextCreated, Deleted, Inserted, Selected, and Updated events of the LinqDataSource control.

If the data operation completed successfully, the resulting data object is stored in the Result property and the Exception property is null. If the data operation failed, the exception that occurred during the data operation is stored in the Exception property and the Result property is null. If you handled the exception represented by the Exception property, set the ExceptionHandled property to true so that the exception will not be thrown.

You retrieve the total number of data records returned from a query through the TotalRowCount property.

Constructors

LinqDataSourceStatusEventArgs(Exception)

Initializes a new instance of the LinqDataSourceStatusEventArgs class by using an exception that occurred as a result of the data operation.

LinqDataSourceStatusEventArgs(Object, Int32)

Initializes a new instance of the LinqDataSourceStatusEventArgs class with an object that contains the data from the data operation and the number of rows returned.

LinqDataSourceStatusEventArgs(Object)

Initializes a new instance of the LinqDataSourceStatusEventArgs class by using an object that contains the data from the data operation.

Properties

Exception

Gets the exception that was thrown during the data operation.

ExceptionHandled

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

Result

Gets the object that represents the result of a data operation.

TotalRowCount

Gets the total number of rows in a data set from a data-retrieval operation.

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