给DataGrid的删除按钮添加"删除确认"对话框

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

         {

              foreach(TableCell tc in e.Item.Cells)//枚举该行中的每个单元格

              {

                   if(tc.Controls.Count>0)//检查每个单元格中的控件数

                   {

                       foreach(Control con in tc.Controls)//得到每个控件

                       {

                            if(con.ToString()=="System.Web.UI.WebControls.DataGridLinkButton")//检查每个控件,看是否是DataGridLinkButton

                            //奇怪的是在System.Web.UI.WebControls中没有这个类,我是通过Response.Write(con.ToString())发现的

                            {

                                 LinkButton lb=(LinkButton)con;

                                 if(lb.CommandName=="Delete")

                                 {

                                     lb.Attributes.Add("onclick", "return confirm('您真的要删除此行吗?')");

                                 }

                            }

                       }

 

                   }

              }

             

         }

 

posted @ 2004-02-11 12:46  dudu  阅读(6354)  评论(16编辑  收藏  举报