首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于gridview的行链接与CommandField删除的冲突有关问题,解决

2012-04-08 
关于gridview的行链接与CommandField删除的冲突问题,请教高手解决gridview绑定数据,在最后一列添加Command

关于gridview的行链接与CommandField删除的冲突问题,请教高手解决
gridview绑定数据,在最后一列添加CommandField删除列。为gridview添加行链接后,若要删除gridview中的某行,单击“删除”后会出现:打开确认对话框,触发gridview1_RowDeleting事件,然后还要打开Reply.aspx?ID=XX的窗口。

问题:如何实现在单击“删除”后只打开确认对话框,触发gridview1_RowDeleting事件,不打开Reply.aspx?ID=XX的窗口。请教高手解决

代码如下:

C# code
    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 + "\"的信息吗?')");            }        }    }


[解决办法]
gridview1_RowDeled事件中,

Response.Redirect("Reply.aspx?ID=XX");写
[解决办法]
e.Row.Attributes.Add("onclick", "window.location.href='Reply.aspx?ID=" + this.gridview1.DataKeys[e.Row.RowIndex].Value + "'");

去掉就可以了
[解决办法]
那就不能做行链接了吧,像删除一样对每个单元格做链接吧
[解决办法]
把Row_DataBound事件中的代码,如下;移动到Row_Command事件中
C# code
//为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="+你要传递的参数);        }       } 

热点排行