LinqDataSourceInsertEventArgs 類別

定義

提供 Inserting 事件的資料。

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

範例

下列範例顯示 事件的處理常式 Inserting 。 屬性中的 NewObject 物件會轉換成名為 Product 的類型。 物件的 DateModified 屬性 Product 會設定為目前的日期和時間。

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

下列範例顯示 事件的事件處理常式 Inserting 。 它會使用 Label 控制項顯示任何驗證例外狀況訊息。

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;  
    }  
}  

備註

物件 LinqDataSourceInsertEventArgs 會傳遞至事件的任何事件處理常式 Inserting 。 屬性 NewObject 包含要插入的資料。

您可以使用 LinqDataSourceInsertEventArgs 物件,在資料來源中執行插入作業之前檢查資料。 然後,您可以驗證資料、檢查資料類別中的驗證錯誤,或在更新之前變更值。 您也可以取消插入作業。

如果代表資料來源的 物件在插入資料之前擲回驗證例外狀況,則 Exception 屬性會包含 類別的 LinqDataSourceValidationException 實例。 您可以透過 InnerExceptions 屬性擷取所有驗證例外狀況。 如果未擲回驗證例外狀況,屬性 Exception 會包含 null 。 如果您處理驗證例外狀況,而且不想要重新擲回例外狀況,請將 ExceptionHandled 屬性設定為 true

建構函式

LinqDataSourceInsertEventArgs(LinqDataSourceValidationException)

初始化 LinqDataSourceInsertEventArgs 類別的新執行個體,並指定提供的例外狀況。

LinqDataSourceInsertEventArgs(Object)

初始化 LinqDataSourceInsertEventArgs 類別的新執行個體。

屬性

Cancel

取得或設定值,這個值表示是否應該取消事件。

(繼承來源 CancelEventArgs)
Exception

取得插入作業之前的資料驗證期間所擲回的例外狀況。

ExceptionHandled

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

NewObject

取得包含要插入之資料的物件。

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於