如何修改DetailsView中ItemUpdating Event中的输入数据? [英] How to modify input data in ItemUpdating Event of Detailsview?

查看:197
本文介绍了如何修改DetailsView中ItemUpdating Event中的输入数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能指引我如何在ItemUpdating事件中访问DetailsView的输入数据?


我想对用户输入到Detailsview的数据进行一些修改。
谢谢

解决方案

DetailsView control's ItemUpdating 事件具有包含原始数据(如果可用)的参数以及用户键入的新数据。以下是如何检查数据并可选择修改的示例:

  private void OnDetailsViewItemUpdating(object sender,DetailsViewUpdateEventArgs e){
if(String.Equals((string) NewValues [firstName],john,StringComparison.OrdinalIgnoreCase)){
//John不是有效的名称,所以将其更改为Steve:
e.NewValues [firstName ] =史蒂夫;
}
if(String.Equals((string)e.NewValues [lastName],doe,StringComparison.OrdinalIgnoreCase)){
//如果Doe是最后一个名称,取消整个操作
e.Cancel = true;
}
}

请参阅MSDN了解更多有关 DetailsViewUpdateEventArgs 类型。


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

解决方案

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.

这篇关于如何修改DetailsView中ItemUpdating Event中的输入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆