How to modify input data in ItemUpdating Event of Detailsview?
Ca开发者_如何学Gon 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 youThe 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.
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.
精彩评论