为DataGrid添加确认删除的对话框
作者: 孟宪会
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=81277B42-361C-4FAB-9A1E-B661ABE517F5http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=D4F5E756-0D33-402D-B40D-48E657BD3D4Fhttp://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=9EEAFE96-3393-4228-A19C-C85A1456D104

解决方案 »

  1.   

    e.Item.Cells(10).Attributes.Add("onclick", "return confirm('您确定要删除这一项吗?');")
    写在DataGrid1_ItemDataBound中
    把delete语句写在DeleteCommand中
      

  2.   

    del.Attributes.Add ("OnClick","return confirm('你确信要删吗?')");del为服务器端控件的编号
      

  3.   

    参考一下:
    在DataGrid中添加一个ButtonColumn,比如添加在第一列,CommandName="Delete",ButtonType="LinkButton"
    然后在DataGrid的ItemDataBound事件中:public void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs E)
      {
         if (e.Item.ItemIndex >= 0)
            {
       ((LinkButton)e.Item.Cells[0].Controls[0]).Attributes["onClick"] = "javascript:return confirm('Are you sure delete?');";
            }
      }