我在GridView中点删除时
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton db = (LinkButton)e.Row.Cells[5].Controls[0];
db.OnClientClick = "return confirm('是否删除?')";
}
点一下就出来了
但我在一个按钮里 ((Button)sender).OnClientClick = "return confirm('确定全部删除?')"; 点两下才出来,代码都一样应该(按钮是实现全部删除的)
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton db = (LinkButton)e.Row.Cells[5].Controls[0];
db.OnClientClick = "return confirm('是否删除?')";
}
点一下就出来了
但我在一个按钮里 ((Button)sender).OnClientClick = "return confirm('确定全部删除?')"; 点两下才出来,代码都一样应该(按钮是实现全部删除的)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Attributes.Add("onclick", "return confirm('你确认要删除吗?')"); } }
天天有人在问这样的问题.....
http://topic.csdn.net/u/20090909/11/3584ed0d-baca-4b6d-bcb9-f1c438f4b6ee.html
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imgDelete = e.Row.FindControl("ibtnDel") as ImageButton;
imgDelete.Attributes.Add("onclick", "return confirm('是否真的删除?')");
}
}
其中ibtnDel是你自己添加在每条数据后面的ImageButton
这是一个赋植的过程,而不是立即弹出对话框.
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Attributes.Add("onclick", "return confirm('你确认要删除吗?')"); } }
在加载页面上加上这脚本代码就能实现删除提示了,非常好用的哦
protected void Page_Load(object sender, EventArgs e)
{
btndel.Attributes.Add("onclick", @"javascript:if(confirm('你是否真的要删除?')){return true;}else{return false;}");
}
{
LinkButton db = (LinkButton)e.Row.Cells[5].Controls[0];
db.OnClientClick = "return confirm('是否删除?')";
}
这段代码是在rowdatabound事件里的吧,这样点删除之前按钮已经有onclientclick属性了