How to modify input data in ItemUpdating Event of Detailsview?

一世执手 提交于 2019-12-08 06:17:33

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1992660/how-to-modify-input-data-in-itemupdating-event-of-detailsview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!