在RowDeleting()事件中 使用js脚本提示确认删除和取消,为什么按取消还是删除了数据,有什么办法修改吗?谢谢

解决方案 »

  1.   

    在RowDataBound 或者RowCreated事件里 验证
      

  2.   

    Response.Write("<script>confirm('是否删除')</script>");
      

  3.   

    return confirm("确定删除吗")lz可能是没有return 
      

  4.   

    up
    放在button的OnClientClick里面,OnClientClick='return confirm("确定删除吗")'
      

  5.   

    是GRIDVIEW控件里添加的删除BUTTON 怎么用ONCLIENCLICK事件啊?
      

  6.   

    在gridview上添加 TemplateField ,事件选择Delete,然后在RowDeleting()事件中写删除操作就可以,下面是代码供参考
    <asp:TemplateField HeaderText="删除">
     <ItemTemplate>
     <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete"
          OnClientClick="return confirm('确定删除?');"  Text="删除"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
      

  7.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((LinkButton)e.Row.Cells[9].Controls[0]).Attributes.Add("onclick", "return confirm('你确定要删除该用户吗?');");
            }
        }
      

  8.   

    Response.Write(" <script>confirm('是否删除') </script>");这样肯定不行了,因为这Response.Write是在整个页面执行完后才实行的,所以应该把confirm('是否删除') 放到客户端中
      

  9.   

    這個事件應該寫在RowDataBound里面protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                ((BUTTON )e.Row.FindControl("butonid")).Attributes.Add("onclick", "if(!confirm('你确定要删除该用户吗?')) return false;"); 
            } 
        }