当前位置:编程学习 > C#/ASP.NET >>

datatable中取消事件的问题

在datatable中使用了个事件:rowchanged,因为需要修改datatable某一行的值,为了不循环触发该事件,我在绑定的方法中使用了取消该委托的绑定,但是实际使用时,发现取消绑定并未成功,仍然循环.请问这种情况下该如何取消该事件.部分代码如下:
private void GetAndSetBillOnChange(object sender,System.Data.DataRowChangeEventArgs e)//当帐单或明细发生变化时,对其进行修改。
        {
            BillListDs.Tables[0].RowChanged -= new DataRowChangeEventHandler(GetAndSetBillOnChange);
            ……            
            if (dstemp != null)
            {
                if (dstemp.Tables["BillList"] != null)
                {
                    switch (BillMainpart0.BillTypeId)
                    {
                        case 3:
                            for (int i = 0; i < dstemp.Tables["BillList"].Rows.Count; i++)
                            {
                                DataRow dr = this.BillListDs0.Tables["BillList"].Select("id1=" + int.Parse(dstemp.Tables["BillList"].Rows[i]["id1"].ToString()))[0];
                                sum = (dr["金额"].ToString() == "") ? "0" : dr["金额"].ToString();
                                nums = (dr["数量"].ToString() == "") ? "0" : dr["数量"].ToString();
                                price = (dr["单价"].ToString() == "") ? "0" : dr["单价"].ToString();
                                decimal tax = decimal.Parse(sum) - decimal.Parse(nums) * decimal.Parse(price);
                                
                                dr["税金额"] = tax;

                                if (decimal.Parse(nums) * decimal.Parse(price) > 0)
                                {
                                    dr["税率"] = (decimal.Parse(sum) - decimal.Parse(nums) * decimal.Parse(price))
                                        / (decimal.Parse(nums) * decimal.Parse(price)) * 100;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    ReComputeBill();//帐单明细发生改变时,重新计算帐单的各项金额
                }
            }
            BillListDs.Tables[0].RowChanged += new DataRowChangeEventHandler(GetAndSetBillOnChange);
        } --------------------编程问答-------------------- else 
  exit for --------------------编程问答-------------------- 什么意思?不明白,能说得详细点吗?
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,