LinqDataSourceStatusEventArgs 類別

定義

提供 ContextCreatedDeletedInsertedSelected 以及 Updated 事件的資料。

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

範例

下列範例顯示 事件的事件處理常式 Inserted 。 在事件處理常式中 Exception ,如果 屬性為 null ,則會從 屬性中的 Result 物件擷取產品識別碼。 產品識別碼是資料表的主鍵,而且是由資料庫設定,因此在插入作業完成之前,不會知道此值。 如果 屬性不等於 nullException 則會記錄例外狀況訊息。 屬性 ExceptionHandled 接著會設定為 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

備註

類別 LinqDataSourceStatusEventArgs 可讓您檢查控制項所 LinqDataSource 執行之資料作業的結果。 物件 LinqDataSourceStatusEventArgs 會傳遞至 控制項之 ContextCreatedDeletedInsertedSelectedUpdated 事件的 LinqDataSource 事件處理常式。

如果資料作業順利完成,產生的資料物件會儲存在 屬性中 Result ,而 Exception 屬性為 null 。 如果資料作業失敗,資料作業期間發生的例外狀況會儲存在 屬性中 Exception ,而 Result 屬性為 null 。 如果您已處理 屬性所代表的 Exception 例外狀況,請將 屬性設定 ExceptionHandledtrue ,以便不會擲回例外狀況。

您可以擷取透過 TotalRowCount 屬性從查詢傳回的資料記錄總數。

建構函式

LinqDataSourceStatusEventArgs(Exception)

使用因為資料作業而發生的例外狀況,初始化 LinqDataSourceStatusEventArgs 類別的新執行個體。

LinqDataSourceStatusEventArgs(Object)

使用包含資料作業所產生資料的物件,初始化 LinqDataSourceStatusEventArgs 類別的新執行個體。

LinqDataSourceStatusEventArgs(Object, Int32)

使用包含資料作業所產生資料和所傳回資料列數的物件,初始化 LinqDataSourceStatusEventArgs 類別的新執行個體。

屬性

Exception

取得在資料作業期間擲回的例外狀況。

ExceptionHandled

取得或設定值,這個值表示是否處理了例外狀況以及是否不應再度擲回此例外狀況。

Result

取得表示資料作業結果的物件。

TotalRowCount

取得資料擷取作業中資料集的資料列總數。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於