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 + "\"的信息吗?')"); }
} }
{
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 + "\"的信息吗?')"); }
} }
解决方案 »
- 谁能帮忙看看 这个能不能存在注入?
- 急!像新浪财经期货价格的曲线走势图如何做???
- try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后?
- 用户控件位置不固定
- 有个关于 数据循环显示的问题。。在线等。。。谢谢。。。
- 在javascript中转化数据的格式
- .net js老是报错,请高手执教
- ⊙_⊙aspnetpager分页控件,点第二页时,成员变量哈希表就没有值了,请问如何解决?
- 无法向会话状态服务器发出会话状态请求。
- 动态生成层????
- Repeater里面嵌套一个Repeater 做分类控件
- 怎样用JS在Default.aspx页获取多个Checkbox的ID值并构造字符串传递给Default.aspx.cs页
[/Quot这行代码去掉不是就把行链接去掉了?
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;}");
第1种方法,去掉那一行代码后,就把行链接去掉了。
您说的第2种方法我试了一下,还是不行。删除行后,还是会打开Reply.aspx?ID=XX链接,望赐教!
还是会打开Reply.aspx?ID=XX链接?
你写这个Reply.aspx的目的是干什么的啊?删除内容为什么写一个新的页面?
你把要处理的内容写在
gridview1_RowDeleting事件
里面不是就可以了?
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="+你要传递的参数);
}
}