protected void UniGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
           ImageButton deluser = (ImageButton) UniGridView.Rows[e.RowIndex].FindControl("ImageButton2");
           deluser.OnClientClick = "return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
            int index=e.RowIndex ;
            GridViewRow gvr=UniGridView.Rows[index];
            string userName = gvr.Cells[1].Text;
            User currentUser2 = new User(userName);            
            currentUser2.Delete();
            UniGridView_DataBind();
        }

解决方案 »

  1.   

    你指望这句提示吗?
     deluser.OnClientClick = "return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")"; 
    这一句应在窗体Load的时候就应执行了,你在RowDeleting才有好像太晚了。
      

  2.   

    你试着在RowBound事件里来把OnClickClick方法注册上,这样可能会更好些。比如:string js = "return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")");  deluser.Attribute.Add(onclick, js);
      

  3.   

    Load时deluser如何找到,我写的取不到值 
      

  4.   

            protected void UniGridView_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                ImageButton deluser = (ImageButton)e.Row.FindControl("ImageButton2");
                string js = "javascript:return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
                deluser.Attributes.Add("onclick", js);
            }
    出错:未将对象引用设置到对象的实例,在deluser.Attributes.Add("onclick", js);
      

  5.   

    在RowBound事件里添加如下代碼
    ImageButton deluser =(ImageButton)e.Item.FindControl("ImageButton2") ;
    string js = "<script language='javascript'>return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")</script>");  
    if(deluser!=null)
    {
     deluser.Attribute.Add("onclick", js);
    }
      

  6.   

          protected void UniGridView_RowDataBound(object sender, GridViewRowEventArgs e) 
            { 
                ImageButton deluser = (ImageButton)e.Row.FindControl("ImageButton2"); 
                string js = "javascript:return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")"; 
                deluser.Attributes.Add("onclick", js); 
            } 
    你這句話會出錯是因為你沒有判斷是不是數據行,如果是表頭是找不到那個按鈕的,所以你要么判斷當前行是否是數據行要么判斷取得的ImageButton是否為空
      

  7.   


    private void dg_ddl_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    Button delete = (Button)e.Item.FindControl("btnDel");
    delete.Attributes.Add("onclick", "return confirm('您真的要删除吗?');");
                             }
    }
      

  8.   

    在ItemDataBound事件,如果是表头表尾等可能会取不到你的控件,既然你的控件只在行里,那么你可以这样判断:if (e.Row.RowType!=ListItemType.DataRow)
    {
        return;
    }
      

  9.   

    你在运行后查看一下源文件中是否把Confirm这个语句注册到控件上了?
      

  10.   

    或許有用 <ItemTemplate >
                  <tr>
                    <td>
                            <asp:Button ID="btn_DelClass" runat="server" CommandArgument='<%# Eval("[\"BoardID\"]")%> ' CommandName="DelBoard" Text="× 删除版块" OnClientClick="return confirm('确实删除版块吗?删除版块会清除版块下的所有帖子!')"/>                       
                   </td>
                  </tr>
                 </ItemTemplate>
      

  11.   

    OnClientClick="return confirm('<%$ Resources:LocalizedText, User_GridViewActionsDeleteConfirmation %>')"
    取不出来啊,否则倒好办了