LinqDataSourceInsertEventArgs 类     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 Inserting 事件提供数据。
public ref class LinqDataSourceInsertEventArgs : System::ComponentModel::CancelEventArgspublic class LinqDataSourceInsertEventArgs : System.ComponentModel.CancelEventArgstype LinqDataSourceInsertEventArgs = class
    inherit CancelEventArgsPublic Class LinqDataSourceInsertEventArgs
Inherits CancelEventArgs- 继承
示例
以下示例演示 事件的处理程序 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) |