private void OnSqlUpdating(Object source, SqlDataSourceCommandEventArgs e) {
    DbCommand command = e.Command;
    DbConnection cx  = command.Connection;    
    cx.Open();    
    DbTransaction tx = cx.BeginTransaction();
    command.Transaction = tx;
 } private void OnSqlUpdated(Object source, SqlDataSourceStatusEventArgs e) {
    DbCommand command = e.Command;
    DbTransaction tx = command.Transaction;
    
    // In this code example the OtherProcessSucceeded variable represents
    // the outcome of some other process that occurs whenever the data is 
    // updated, and must succeed for the data change to be committed. For 
    // simplicity, we set this value to true. 
    bool OtherProcessSucceeded = true;
    
    if (OtherProcessSucceeded) {
        tx.Commit();
        Label2.Text="The record was updated successfully!";
    }
    else {
        tx.Rollback();
        Label2.Text="The record was not updated.";
    }
 }

解决方案 »

  1.   

    首先,lz提出的问题有错误。从您所列举的代码可以判断出这两个方法不属于GridView(根据SqlDataSourceCommandEventArgs),而是属于SqlDataSource控件。
    前一个方法表示在update数据之前,实现启用事务处理。后一个方法表示在更新完成之后,则判断是否实现了更新。如果更新成功,则并显示相关信息;否则回调,并显示相关信息。
    我们要注意到,在asp.net 2.0中更新数据时,一般不需要显示调用更新方法,这是自动完成的(虽然asp.net 2.0提供了这个方法)。在此,我们重点处理的是更新前后的内容。