LinqDataSourceUpdateEventArgs Classe

Definição

Fornece dados para o evento de Updating .Provides data for the Updating event.

public ref class LinqDataSourceUpdateEventArgs : System::ComponentModel::CancelEventArgs
public class LinqDataSourceUpdateEventArgs : System.ComponentModel.CancelEventArgs
type LinqDataSourceUpdateEventArgs = class
    inherit CancelEventArgs
Public Class LinqDataSourceUpdateEventArgs
Inherits CancelEventArgs
Herança
LinqDataSourceUpdateEventArgs

Exemplos

O exemplo a seguir mostra um manipulador de eventos para o Updating evento.The following example shows an event handler for the Updating event. O exemplo mostra como comparar propriedades da OriginalObject propriedade e da NewObject propriedade para determinar se o valor na Category propriedade foi alterado.The example shows how to compare properties from the OriginalObject property and the NewObject property to determine whether the value in the Category property has changed. Nesse caso, a CategoryChanged Propriedade do objeto na NewObject propriedade é definida como true .If so, the CategoryChanged property of the object in the NewObject property is set to true.

protected void LinqDataSource_Updating(object sender, LinqDataSourceUpdateEventArgs e)
{
    Product originalProduct = (Product)e.OriginalObject;
    Product newProduct = (Product)e.NewObject;

    if (originalProduct.Category != newProduct.Category)
    {
        newProduct.CategoryChanged = true;
    }
}
Protected Sub LinqDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceUpdateEventArgs)
    Dim originalProduct As Product
    Dim newProduct As Product

    originalProduct = CType(e.OriginalObject, Product)
    newProduct = CType(e.NewObject, Product)

    If (originalProduct.Category <> newProduct.Category) Then
        newProduct.CategoryChanged = True
    End If
End Sub

O exemplo a seguir mostra um manipulador de eventos para o Updating evento.The following example shows an event handler for the Updating event. Ele exibe todas as mensagens de exceção de validação usando um Label controle.It displays any validation exception messages by using a Label control.

Protected Sub LinqDataSource_Updating(ByVal sender As Object, _  
        ByVal e As LinqDataSourceUpdateEventArgs)  
    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_Updating(object sender,   
        LinqDataSourceUpdateEventArgs 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;  
    }  
}  

Comentários

O LinqDataSourceUpdateEventArgs objeto é passado para qualquer manipulador de eventos para o Updating evento.The LinqDataSourceUpdateEventArgs object is passed to any event handler for the Updating event. Você pode usar o LinqDataSourceUpdateEventArgs objeto para examinar os dados antes que a operação de atualização seja executada na fonte de dados.You can use the LinqDataSourceUpdateEventArgs object to examine the data before the update operation is executed in the data source. Em seguida, você pode validar os dados, examinar exceções de validação lançadas pela classe de dados ou alterar um valor antes da atualização.You can then validate the data, examine validation exceptions thrown by the data class, or change a value before the update. Você também pode cancelar a operação de atualização.You can also cancel the update operation.

O OriginalObject objeto contém os dados que foram recuperados originalmente da fonte de dados.The OriginalObject object contains the data that was originally retrieved from the data source. O NewObject objeto contém os dados que serão salvos na fonte de dados durante a operação de atualização.The NewObject object contains the data that will be saved in the data source during the update operation.

Se o objeto que representa a fonte de dados lançar uma exceção de validação antes de atualizar os dados, a Exception Propriedade conterá uma instância da LinqDataSourceValidationException classe.If the object that represents the data source throws a validation exception before updating the data, the Exception property contains an instance of the LinqDataSourceValidationException class. Você pode recuperar todas as exceções de validação por meio da InnerExceptions propriedade.You can retrieve all the validation exceptions through the InnerExceptions property. Se nenhuma exceção de validação for gerada, a Exception Propriedade conterá null .If no validation exception is thrown, the Exception property contains null. Se você tratar as exceções de validação e não quiser que a exceção seja relançada, defina a ExceptionHandled propriedade como true .If you handle the validation exceptions and do not want the exception to be re-thrown, set the ExceptionHandled property to true.

Por padrão, o LinqDataSource controle armazena os valores originais da fonte de dados no estado de exibição na página da Web, exceto aqueles cujo ColumnAttribute atributo está marcado como UpdateCheck.Never .By default, the LinqDataSource control stores the original values from the data source in view state on the Web page, except those whose ColumnAttribute attribute is marked as UpdateCheck.Never. LINQ to SQL verifica automaticamente a integridade dos dados antes de atualizar os dados.LINQ to SQL automatically checks the integrity of the data before updating the data. Ele faz isso comparando os valores atuais na fonte de dados com os valores originais armazenados no estado de exibição.It does this by comparing the current values in the data source with the original values stored in view state. LINQ to SQL gerará uma exceção se os valores na fonte de dados tiverem mudado.LINQ to SQL raises an exception if the values in the data source have changed. Você pode executar a validação de dados adicional criando um manipulador para o Updating evento.You can perform additional data validation by creating a handler for the Updating event.

Construtores

LinqDataSourceUpdateEventArgs(LinqDataSourceValidationException)

Inicializa uma nova instância da classe LinqDataSourceUpdateEventArgs com a exceção especificada.Initializes a new instance of the LinqDataSourceUpdateEventArgs class with the specified exception.

LinqDataSourceUpdateEventArgs(Object, Object)

Inicializa uma nova instância da classe LinqDataSourceUpdateEventArgs.Initializes a new instance of the LinqDataSourceUpdateEventArgs class.

Propriedades

Cancel

Obtém ou define um valor que indica se o evento deve ser cancelado.Gets or sets a value indicating whether the event should be canceled.

(Herdado de CancelEventArgs)
Exception

Obtém a exceção gerada enquanto os dados estavam sendo validados antes da operação de atualização.Gets the exception that was thrown while the data was being validated before the update operation.

ExceptionHandled

Obtém ou define um valor que indica se a exceção foi tratada e que ela não deve ser gerada novamente.Gets or sets a value that indicates whether the exception was handled and that it should not be thrown again.

NewObject

Obtém o objeto que contém os valores que serão salvos na fonte de dados.Gets the object that contains the values that will be saved in the data source.

OriginalObject

Obtém o objeto que contém os valores que foram originalmente recuperados da fonte de dados.Gets the object that contains the values that were originally retrieved from the data source.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Aplica-se a