c# 委托

在EXtgrid类中

 public delegate bool DeleteEvent(string selStr);

    public DeleteEvent OnDeleteEvent{get;set;}

  protected void btnDelete_Click(object sender, EventArgs e)     {         DoDelete();     }

    public void DoDelete()     {        

string sel = GetRowsSelected();        

if (sel == "")      

   {             Alert.Show("请选择一条数据!");          

   return;         }      

   if (OnDeleteEvent != null)//委托给使用者实现      

   {            

try            

{                

if (OnDeleteEvent(sel))                

{                     Alert.Show("删除成功!");                     BindGrid();                 }             

    else                

{                     Alert.Show("删除失败!");                 }             }         

    catch            

{                 Alert.Show("删除失败!数据存在引用关系,请查找");             }         }     }

 

在继承Extgrid类的页面中,实现委托删除操作

private bool deleteRecord(string recordID)
  {
     int flag = 0;
   try
   {
    string wherecondition="";
    wherecondition=" where SEQ in("+recordID+")";
                t_access = new B_CardAccess(this.connStr);
                flag=t_access.ExecuteDelRecord(wherecondition);
    this.Log("删除");
    
   }
   catch
   {
               
   }
   if (flag > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
  }

posted on 2015-02-28 10:57  woshare  阅读(116)  评论(0)    收藏  举报