2010-01-02 43 views

回答

4

DetailsView控制的ItemUpdating事件有两个包含原始数据(如果可用)的参数,以及新的数据,用户在键入以下是如何检查的数据,并有选择地修改它的一个例子:

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; 
    } 
} 

请参见MSDN上的DetailsViewUpdateEventArgs类型的详细信息。

0

数据如何绑定到Detailsview?

如果它通过LinqDataSource,SqlDataSource或ObjectDataSource绑定,我建议你看看更新事件。您可以通过EventArgs访问该对象。

e.NewObject或类似的

东西,你可以施放此属性为相应的类型,然后进行更改。

相关问题