views:

379

answers:

2

Hi ,
Can you direct me how can i access input data of DetailsView in ItemUpdating event ?
I want do some modification on data that user input to Detailsview . Thank you

+2  A: 

The DetailsView control's ItemUpdating event has arguments that contain both the original data (if available) as well as the new data that the user typed in. Here's an example of how to check the data and optionally modify it:

private void OnDetailsViewItemUpdating(object sender, DetailsViewUpdateEventArgs e) {
    if (String.Equals((string)e.NewValues["firstName"], "john", StringComparison.OrdinalIgnoreCase)) {
        // "John" is not a valid name, so change it to "Steve":
        e.NewValues["firstName"] = "Steve";
    }
    if (String.Equals((string)e.NewValues["lastName"], "doe", StringComparison.OrdinalIgnoreCase)) {
        // If "Doe" is the last name, cancel the whole operation
        e.Cancel = true;
    }
}

See MSDN for more info on the DetailsViewUpdateEventArgs type.

Eilon
A: 

How is the data bound to the Detailsview?

If it's bound via LinqDataSource, SqlDataSource or ObjectDataSource I suggest you have a look at the Updating Event. There you have access to the object via the EventArgs.

e.NewObject or something like that

You can cast this property into the corresponding type and make your changes.

citronas