我使用以下代码
会弹出提示
但不管你是点确认还是取消
都会删除记录
protected void gdvAssess_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Cells[12].Attributes.Add("onclick", "javascript:return window.confirm('是否确定删除此条记录?');");
}大虾帮我看看是哪里的问题
应该怎么改是不是还要修改下面的代码
protected void gdvAssess_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = int.Parse(((Label)this.gdv_Assess.Rows[e.RowIndex].Cells[1].FindControl("lblID")).Text);
this.AssessCon.Delete(id);
this.gdvAssess_databind();
}
会弹出提示
但不管你是点确认还是取消
都会删除记录
protected void gdvAssess_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Cells[12].Attributes.Add("onclick", "javascript:return window.confirm('是否确定删除此条记录?');");
}大虾帮我看看是哪里的问题
应该怎么改是不是还要修改下面的代码
protected void gdvAssess_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = int.Parse(((Label)this.gdv_Assess.Rows[e.RowIndex].Cells[1].FindControl("lblID")).Text);
this.AssessCon.Delete(id);
this.gdvAssess_databind();
}
解决方案 »
- Asp.NET MVC 传值原理
- asp.net 如何实现瀑布流 效果呢
- socket同步传输数据问题,比较麻烦的问题?急!!
- asp.net中设置配置文件问题
- 公司急聘asp.net专职和兼职人员
- 关于div做的菜单被SVG遮挡的问题
- 求会员推广链接邀请别的用户注册获得积分功能实例??
- ASP.NET解析Json字符串
- 请问 “无法打开 Web 项目“HISHL7/Dict”。 文件路径不符……”这是什么错误?
- DataGrid控件问题,急!!!
- 这里面给datagrid加上删除对话框,什么啊,没有DEL语句怎么删除,治标不治本!!!!!!!!!!!!!!
- [继续关注]如何在gridview中每行的按钮列中为每个按钮添加删除确认按钮呢?
比如e.Row.Cells[12]这控件是一个linkbuttom那要写成((linkbuttom)e.Row.Cells[12].findcontrol["这里是该单元格第几个控件。如果是第一个写"0"]).Attributes.Add("onclick", "javascript:return window.confirm('是否确定删除此条记录?');");
我都是这样写的。毫无问题!!!
加入return confirm('确认删除?')就可以了
或者在aspx的html代码中找到linkbutton,手动输入OnClientClick=“return confirm('确认删除?')”
{
//删除确认
LinkButton delBttn = (LinkButton) e.Item.Cells[7].Controls[0];
delBttn.Attributes.Add("onclick","javascript:return confirm('确定删除?');"); e.Item.Attributes.Add("onmouseover","tdOver(this)");
e.Item.Attributes.Add("onmouseout","tdOut(this)");
}
<asp:LinkButton id="link" runat="server">
<div onclick="javascript:return window.confirm('Message')">链接</div>
</asp:LinkButton>
</ItemTemplate>
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ LinkButton delBtn = (LinkButton)e.Row.Cells[9].Controls[0];
delBtn.Attributes.Add("onclick", "return confirm('确认删除吗?');");
}
}
<asp:LinkButton id="link" runat="server" OnClientClick=“if(confirm('删除?')!=ture)return false”>
e.Row.FindControl(字段id).Attributes["onclick"]="return window.confirm('是否确定删除此条记录?');");
如在命令列同时使用了编辑和删除,并且编辑在删除前面时
点击了编辑而第二个链接变成了取消,导致点击取消出现确认信息
而用FindControl则有可能点击编辑后删除链接变成了取消链接
导致程序运行出错我的解决方法是把命令列转换成模板,直接在模板里给删除链接加OnClientClick<asp:TemplateField HeaderText="操作" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
Text="更新" ValidationGroup="EditValidation"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消"></asp:LinkButton>
</EditItemTemplate>
<ItemStyle Width="20%" />
<ItemTemplate>
<asp:LinkButton ID="edit" runat="server" CausesValidation="False" CommandName="Edit"
Text="编辑"></asp:LinkButton>
<asp:LinkButton ID="delete" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" OnClientClick="return confirm('您确定要删除选中的内容吗?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
{
if (event.srcElement.outerText=="删除")
event.returnValue=confirm("您确定要删除吗?注意:此操作不可恢复,请谨慎操作!");
}
document.onclick=delete_confirm;</script>----------------------------------------------------------
www.cndigs.com掘客园--发掘、推荐软件开发资源,分享、交流技术开发心得
asp.net2.0资料
http://www.cndigs.com/search.php?search=asp.net%202.0&tag=true
asp.net资料
http://www.cndigs.com/search.php?search=asp.net&tag=true
ajax资料
http://www.cndigs.com/search.php?search=ajax&tag=true