我有一个DATAGRID控件,前两列绑定了2个数据库的字段"newsid"和"newstitle",第三列是一个超级连接列,名字是编辑.第四列是一个模版列,添加了一个BUTTON,名称是删除.问题是:现在我想当点击这个删除按扭的时候能出现一个提示!实现:((Button)e.Item.Cells[3].Controls[0]).Attributes.Add("onclick","javascript:return confirm(你确定要删除吗?')"); 
可是没有反应,应该加到DG的什么事件里啊??还忘帮忙啊!

解决方案 »

  1.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) 
    {
    ((Button)e.Item.Cells[3].Controls[0]).Attributes.Add("onclick","javascript:return confirm(你确定要删除吗?')"); 

    }
    }
      

  2.   

    出现这个问题!
    “/Gxs_Yy.net”应用程序中的服务器错误。
    --------------------------------------------------------------------------------指定的转换无效。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。源错误: 
    行 101: if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) 
    行 102: {
    行 103: ((Button)e.Item.Cells[3].Controls[0]).Attributes.Add("onclick","javascript:return confirm(你确定要删除吗?')"); 
    行 104:
    行 105: }
     源文件: f:\asp.netweb\gxs_yy.net\admin\editnews.aspx.cs    行: 103 
    什么原因啊!
      

  3.   

    ((Button)e.Item.FindControls(ID)).Attributes.Add("onclick","javascript:return confirm(你确定要删除吗?')"); 
      

  4.   

    F:\ASP.NetWeb\Gxs_Yy.net\Admin\Editnews.aspx.cs(104): “System.Web.UI.WebControls.DataGridItem”并不包含对“FindControls”的定义
      

  5.   

    换成button 的ID,是这个错误:
    F:\ASP.NetWeb\Gxs_Yy.net\Admin\Editnews.aspx.cs(104): 名称“BtnDel”在类或命名空间“Gxs_Yy.net.Admin.Editnews”中不存在
      

  6.   

    加双引号拉。。((Button)e.Item.FindControls("BtnDel")).Attributes.Add("onclick","javascript:return confirm(你确定要删除吗?')");
      

  7.   

    加了就是F:\ASP.NetWeb\Gxs_Yy.net\Admin\Editnews.aspx.cs(104): “System.Web.UI.WebControls.DataGridItem”并不包含对“FindControls”的定义