增加新记录时ObjectDataSoruce和FormViw中的相关事件使用总结

首先,当在FormView中按下commandName="Insert"的按钮时,.NET先会执行object data source的OnInserted事件。这个事件有一个ObjectDataSourceStatusEventArgs类型的参数:它有几个属性我们会用到:

1. e.Exception --表示增加时发生的异常对象,如果在调用的目标对象上发生异常,查看InnerException对象以取得更多信息。
2. e.ExceptionHandled --表示是否将异常标记为已处理,如果设为true,异常不会传到后面的事件中去。
3. e.ReturnValue --表示你在object data source上设置的InsertMethod返回的值,可以通过此值检查是否成功。

接着,.NET会执行FormView的OnItemInserted事件,如果前面object data source的ExceptionHandled没有被设为true,那么Exception会传入这个事件中,此事件有一个FormViewInsertedEventArgss类型的参数:它有几个属性我们会用到:
1. e.ExceptionHandled --表示是否将异常标记为已处理,如果设为true,异常不会传到后面的Page.Error事件中去。否则如果定义了Page.Error事件,先执行Page.Error事件,如果Page.Error没有执行Server.ClearError()方法,异常再传入Application_Error事件中去.未定义Page.Error事件处理程序时,直接传入Application_Error事件中。
2. e.KeepInInsertMode --是否保持Insert模式中,通常如果出错,我们会显示一个错误信息,保持在Insert模式方便用户修改

 

None.gif
None.gif    
protected   override   void  OnError(EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
//If fvFixingResult_ItemInserted and objdsFixingResult_Inserted
InBlock.gif        
//didn't set ExceptionHandled = true, this event will be called.
InBlock.gif
        Exception ex = Server.GetLastError();
InBlock.gif        
if (ex != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            lblErrorMessage.Text 
= ex.Message;
ExpandedSubBlockEnd.gif        }

InBlock.gif        Server.ClearError();
ExpandedBlockEnd.gif    }

None.gif
None.gif    
protected   void  fvFixingResult_ItemInserted( object  sender, FormViewInsertedEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
if (!e.ExceptionHandled && e.Exception != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            e.ExceptionHandled 
= true;
InBlock.gif            e.KeepInInsertMode 
= true;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CloseWindow();
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif
None.gif    
protected   void  objdsFixingResult_Inserted( object  sender, ObjectDataSourceStatusEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
if (e.Exception != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//e.ExceptionHandled = true;
InBlock.gif
            LogManager.AddActivity("Add <Fixing Result - ELNZC>"false);
InBlock.gif            
if (e.Exception.InnerException != null && e.Exception.InnerException is FixingDateDuplicatedException)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                FixingDateDuplicatedException fx 
= e.Exception.InnerException as FixingDateDuplicatedException;
InBlock.gif                lblErrorMessage.Text 
= MessageManager.GetMessage(fx.MessageID, Language).MessageDesc;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                lblErrorMessage.Text 
= MessageManager.GetMessage(SysMessage.COMMON_SAVE_FAILED, Language).MessageDesc;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            LogManager.AddActivity(
"Add <Fixing Result - ELNZC>, data key: " + e.ReturnValue);
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

 

posted on 2007-06-13 11:46  阿牛-专注金融行业开发 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/rockniu/archive/2007/06/13/781615.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值