以下是我的代码,我要删除的信息有被推荐或未被推荐之分。当删除被推荐的信息时,我想做一个询问是否真的要删除的功能。
最好是弹出一个对话框,点确定就删除,点取消就不再执行。
isre()//这个函数是返回BOOL值, true为被推荐, false为未推荐。
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.RowIndex][0].ToString();
        int T_id = Convert.ToInt32(id);
        tr.del_train(T_id);
        Message.showmessage("删除成功!");
        getdata();
       
    }
各位帮帮忙!!

解决方案 »

  1.   

     Button1.Attributes.Add("onclick", "return confirm('xxxx')");
    数据绑定的时候给每个执行操作的按钮加上。
      

  2.   

    http://www.cnblogs.com/doraeimo/archive/2007/01/01/609344.html
    http://www.cnblogs.com/DotNet1010/archive/2008/04/08/1142527.html
    请看
      

  3.   

    <asp:LinkButton ID="LinkButton1" runat="server"  CommandName="Delete"
                           OnClientClick="return confirm('确定要删除吗?')" Text="删除"></asp:LinkButton>
      

  4.   


    <asp:Button ID="Button1" runat="server" Text="Button"  OnClientClick="return confirm('确定删除吗?')"  onclick="Button1_Click" />
      

  5.   

    那你应该在绑定的时候做些判断,是推荐的话你就要绑定为
    <asp:LinkButton ID="LinkButton1" runat="server"  CommandName="Delete"
                           OnClientClick="return confirm('确定要删除吗?')" Text="删除"></asp:LinkButton>
    不是就不用加哪个事件,是可以解决的
    也可以在.CS代码里面判断:
    if(是推荐)
    {
     response.write("<script>confirm('确认要删除吗?');</script>");
    }
      

  6.   


    js前台
    <script>
    var obj = <%=isre()%>;  //注意这里的方法在CS后台是公共的方法,并且是返加TRUE,或FASLE的.
    if(obj==true)
    {
       return comfirm("是否删除?");
    }
    else
    {
        return false;
    }
    </script>
      

  7.   

    拜托推荐的一样可以啊
    rowdatabound事件写个判断
    if(e.RowIndex>=0)
    {
       if(推荐)
       {
         Button btn = (Button)e.FindControl("buttonID");
         btn.attributes.add("onclick","return confirm(' delete?');");
    }
    }
      

  8.   

    string id = this.GridView1.DataKeys[e.RowIndex][0].ToString(); 
    int T_id = Convert.ToInt32(id); if (GridView1.rows(T_id ).cells(推荐列)=='推荐')
    {
    Button1.Attributes.Add("onclick", "return confirm('xxxx')"); }
     
      

  9.   

    在GridView1_RowDataBound事件中
     if (e.Row.RowType == DataControlRowType.DataRow)
        {          
           if(你的条件!)
            {
                ((LinkButton)e.Item.Cells[6].Controls[0]).Attributes.Add("onclick", "return confirm('你确定要删除该信息类型吗?');");        }
         }
      

  10.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 

            string id = this.GridView1.DataKeys[e.Row.RowIndex][0].ToString(); //同样根据当前列索引获得datakey关联值
            if(e.Row.RowType == DataControlRowType.DataRow)
            {
                Button btn = (Button)e.FindControl("buttonID"); //操作的按钮或其他控件
                if(btn != null)
                {
                   //如果isre()函数需要根据关联id来判断可以在此进行操作
                   if(isre()){btn.attributes.add("onclick","return confirm('确定删除');"); }
                }
            }      

      

  11.   

    //由于OnClientClick屬性只在Button按鈕控件上才有,所以你需要創建一個模板列字段用來加
        //入Button按鈕,并設置Button的Onclick屬性為"return confirm('確定刪除數據行?')",這
        //樣就可以了,在前臺也可以如下這樣寫.不過你還是需要一個模板列
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 
        { 
            string id = this.GridView1.DataKeys[e.RowIndex][0].ToString(); 
            int T_id = Convert.ToInt32(id); 
            tr.del_train(T_id); 
            if (isre() == true)
            {
                Button Button1 = (Button)e.FindControl("你前臺模板列里的ButtonID"); 
                Button1.Attributes.Add("onclick", "return confirm('xxxx')");
            }
            getdata();
        }
      

  12.   

    楼上的出现了错误啊
    编译器错误信息: CS0117: “System.Web.UI.WebControls.GridViewRowEventArgs”并不包含“FindControl”的定义源错误: 行 196:        if (e.Row.RowType == DataControlRowType.DataRow)
    行 197:        {
    行 198:            LinkButton btn = (LinkButton)e.FindControl("LB");
    行 199:            if (btn != null)
    行 200:            {
     源文件: d:\Grow18\pages\admin\train\edit_train_info.aspx.cs    行: 198 
      

  13.   


    不好意思忘了,是这样,呵呵 LinkButton btn = (LinkButton)e.Row.FindControl("LB"); 
      

  14.   

    LinkButton btn = (LinkButton)e.Rows[e.rowindex].cells[按钮列序号].FindControl("LB");