<asp:GridView ID="GridView1" runat="server" SkinID="gridviewSkinA" OnRowDataBound="GridView1_RowDataBound"
                            OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowDeleting="GridView1_RowDeleting">
                            <Columns>
                                <asp:CommandField SelectText="查看详细" ShowSelectButton="True" />
                                <asp:BoundField DataField="workername" HeaderText="经手人" />
                                <asp:BoundField DataField="work_date" HeaderText="日期" DataFormatString="{0:yyyy-MM-dd}"
                                    HtmlEncode="False" />
                                <asp:BoundField DataField="work_time" HeaderText="时间" DataFormatString="{0:HH:mm}"
                                    HtmlEncode="False">
                                    <ItemStyle Width="50px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="work_type" HeaderText="工作类型">
                                    <ItemStyle Width="60px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="subject" HeaderText="主题">
                                    <ItemStyle Width="120px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="content" HeaderText="内容">
                                    <ItemStyle Width="200px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="re" HeaderText="备注">
                                    <ItemStyle Width="120px" />
                                </asp:BoundField>
                                <asp:TemplateField ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                                            OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
 
我明明已经取消了,还是会删除项的。
求救中...

解决方案 »

  1.   

    取消也进后台了??断点看下呢
     OnClientClick="return confirm('确认要删除吗?');"
    这样呢
      

  2.   

    return confirm('你是否真的要执行此操作?');
      

  3.   


    <asp:TemplateField ShowHeader="False">
        <ItemTemplate>
          <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="Delete"
           OnClientClick='if(confirm("是否删除该条记录?")) return true ;else return false ;'      Text="删 除" />
        </ItemTemplate>
     </asp:TemplateField>
      

  4.   

    <asp:TemplateField HeaderText="删除">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnDel" runat="server" CommandName="Delete" OnClientClick="return confirm('确认要删除吗?');" CausesValidation="False">删除</asp:LinkButton>
                            </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                        <FooterStyle HorizontalAlign="Center" />
                    </asp:TemplateField>
    ------
    顶,跟我的写法一样啊,不知道为什么了
      

  5.   

    代码逻辑的问题
    因为你执行的是  deleting 事件
    然后你在linkbutton上绑定的  脚本 所以它两个都执行的那么你就得把  删除的代码写在 按钮中就可以了
     那么 你就把 前台的代码改成<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName=‘<%Eval("ID")%>’                                            OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除">然后后台 就在linkbutton的事件中写,获取ID
    string ID=((LinkButton)sender).CommandName.ToString();然后再根据ID 删除就ok了
      

  6.   

    加重点 颜色没有加上 呵呵 不好意思啊 。<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" [color=#FF0000]CommandName=‘<%Eval("ID")%>’  
      

  7.   

    lz的在我这没问题
    不过,我通常写作
    OnClientClick="return confirm('确认要删除吗?');"
      

  8.   

    事件错误
    OnRowDeleting="GridView1_RowDeleting" 这个事件改成 OnRowCommand="GridView_Project_RowCommand" 后台:
    if (e.CommandName.ToString() == "Delete_F")
            {
                DataTable dt = new DataTable();
                string ProjectId = e.CommandArgument.ToString();
                dt = bf.CheckThisGczzt(ProjectId);
                //判断该工程是否有审计工程
                if (dt.Rows.Count == 0)
                {
                    try
                    {
                        DataTable dt1 = new DataTable();
                        dt1 = bfUnitProject.CheckProjectId(ProjectId);
                        if (dt1 != null && dt1.Rows.Count > 0)
                        {
                            if (int.Parse(dt1.Rows[0]["IsexistPro"].ToString()) == 0)
                            {
                                bf.DeleteProject(ProjectId);
                            }
                            else
                            {
                                Response.Write("<script >alert('该工程存在与某个评审流程之中!');</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script >alert('删除失败!');</script>");
                        }
                    }
                    catch
                    {                }
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('存在该工程的审计工程!');</script>");
                }
                BindData();        }
      

  9.   

    IE -> 工具 -> 选项 -> 一般 (不知道中文是不是这么叫,一般默认就显示这个选项卡)
    看中间:
    临时文件下有
    删除Cookie    删除文件     设定
    点中间的删除文件就是删除缓存了(由于我的系统不是中文的,所以都是翻译后的,不见得一模一样,意思应该没错)
      

  10.   

    好痛苦啊,为什么还是这样的,不管确定还是取消,都会执行后台的GridView1_RowDeleting,
    其实这样是肯定不会错的,以前我也是这样写的,但是在我的这个里面就老是会出错。
    <asp:TemplateField ShowHeader="False">
    <ItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
    OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
      

  11.   

    提供一种解决方法:
    界面增加一个事件:OnRowCreated="GridView1_RowCreated"<asp:GridView ID="GridView1" runat="server" SkinID="gridviewSkinA" OnRowDataBound="GridView1_RowDataBound"                            OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
    OnRowDeleting="GridView1_RowDeleting" 
    OnRowCreated="GridView1_RowCreated" >                        后台代码:protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton btnDel = (LinkButton)e.Row.Cells[8].Controls[0];
                    btnDel.Attributes.Add("onclick", "return confirm('确认要删除吗?');");
                }
            }
    原来界面的OnClientClick事件就不用了