取消GridView取消“确认删除”弹窗时报错解决方法
取消GridView取消“确认删除”弹窗时报错
((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('确认删除?')");
Gv.EditIndex = -1;
点确认,没问题,记录也确实从数据库删除了,也执行了DataBound里的重新显示GridView的记录 。。
但是,点取消时,就报错了。。
请高人指点。。还缺啥?
------解决方案--------------------
((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('确认删除?')");
Gv.EditIndex = -1;
点确认,没问题,记录也确实从数据库删除了,也执行了DataBound里的重新显示GridView的记录 。。
但是,点取消时,就报错了。。
请高人指点。。还缺啥?
------解决方案--------------------
- C# code
protected void Gv_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lbl = (LinkButton)e.Row.FindControl("yourcontrolid"); lbl.Attributes.Remove("onclick"); lbl.Attributes.Add("onclick", "return confirm('确认删除?');"); } }
------解决方案--------------------
((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "if(!confirm('确认删除?')){return false;}");
------解决方案--------------------
------解决方案--------------------
我错了,是RowDataBound事件
- C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow gvRow = e.Row; LinkButton lbtnClick = gvRow.FindControl("按钮名称"); lbtnClick.OnClientClick = "return confirm('确认删除?')"; }
------解决方案--------------------
- C# code
LinkButton lbtnClick = gvRow.FindControl("按钮名称") as LinkButton;
------解决方案--------------------
这个是没有问题的!你可以试试
- C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //如果是绑定数据行 if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) { ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')"); } } }
------解决方案--------------------
嗯,楼上的似乎都回答了