gridview绑定数据,在最后一列添加CommandField删除列。为gridview添加行链接后,若要删除gridview中的某行,单击“删除”后会出现:打开确认对话框,触发gridview1_RowDeleting事件,然后还要打开Reply.aspx?ID=XX的窗口。问题:如何实现在单击“删除”后只打开确认对话框,触发gridview1_RowDeleting事件,不打开Reply.aspx?ID=XX的窗口。请教高手解决代码如下:    protected void gridview1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //鼠标经过时,行背景色变 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2FF68'");
            //鼠标移出时,行背景色变 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");            e.Row.Attributes.Add("style", "cursor: hand;");//将光标设为手形            //为gridview添加行链接
            e.Row.Attributes.Add("onclick", "window.location.href='Reply.aspx?ID=" + this.gridview1.DataKeys[e.Row.RowIndex].Value + "'");            //删除时弹出确认对话框 
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                ((LinkButton)e.Row.Cells[7].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除编号是:\"" + e.Row.Cells[1].Text + "\"的信息吗?')");            }
        }    }

解决方案 »

  1.   

    gridview1_RowDeled事件中,Response.Redirect("Reply.aspx?ID=XX");写
      

  2.   

     e.Row.Attributes.Add("onclick", "window.location.href='Reply.aspx?ID=" + this.gridview1.DataKeys[e.Row.RowIndex].Value + "'");去掉就可以了
      

  3.   

    [Quote=引用 2 楼  的回复:] e.Row.Attributes.Add("onclick", "window.location.href='Reply.aspx?ID=" + this.gridview1.DataKeys[e.Row.RowIndex].Value + "'");去掉就可以了
    [/Quot这行代码去掉不是就把行链接去掉了?
      

  4.   

    办法有2
    1,GridView删除事件本身不需要这些代码,里面可以得到要删除的id的(DataKey)
    2,你可以
    ((LinkButton)e.Row.Cells[7].Controls[0]).Attributes.Add("onclick", "if( confirm('你确认要删除编号是:\"" + e.Row.Cells[1].Text + "\"的信息吗?')){ window.location.href='Reply.aspx?ID=" + this.gridview1.DataKeys[e.Row.RowIndex].Value + "';}else{return false;}");
      

  5.   

    to:net_lover
    第1种方法,去掉那一行代码后,就把行链接去掉了。
    您说的第2种方法我试了一下,还是不行。删除行后,还是会打开Reply.aspx?ID=XX链接,望赐教!
      

  6.   

    你是什么意思啊?
    还是会打开Reply.aspx?ID=XX链接?
    你写这个Reply.aspx的目的是干什么的啊?删除内容为什么写一个新的页面?
    你把要处理的内容写在
    gridview1_RowDeleting事件
    里面不是就可以了?
      

  7.   

    我想要实现的效果是:单击gridview1某一行,链接打开一个页面,即Reply.aspx?ID=XX页面。在行里面还有一列,即CommandField删除列,单击某行的删除列,就把该行删除,这个在gridview1_RowDeleting事件里有删除代码。现在的问题是:单击行打开链接这个功能要有,但是删除某行的同时,程序还会打开Reply.aspx?ID=XX页面链接,如何取消?
      

  8.   

    把Row_DataBound事件中的代码,如下;移动到Row_Command事件中//为gridview添加行链接
                e.Row.Attributes.Add("onclick", "window.location.href='Reply.aspx?ID=" + this.gridview1.DataKeys[e.Row.RowIndex].Value + "'");Row_Command事件代码如下:
    protected void gvRoom_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandArgument=="show")
            {
               Page.Server.Transfer("Reply.aspx?ID="+你要传递的参数);        
    }   
        }