gridview上的javascript删除链接 [英] javascript on gridview delete link

查看:58
本文介绍了gridview上的javascript删除链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在gridview.i中放置了autogeneratDelete按钮,必须在此链接上应用javascript .Ex:当我点击删除链接对话框打开并要求确认删除。

i试试这个,但是它没有正常工作。当我第一次点击时它不会打开对话框,当我点击第二次对话框打开但是当我点击取消时,那么数据也会被删除。



i have put autogeneratDelete button in gridview.i have to apply javascript on this link.Ex: when i click on delete link dialog box open and ask for confirm to delete.
i have try this,but it is not working properly.when i click first time it will not open dialog box ,when i click second time dialog box is open but when i click on cancel ,then also data will be deleted.

GridView1.Attributes.Add("onclick", "javascript:confirmDelete(''Server ID'')");





i已将javascript放入.js文件。



i have put javascript in .js file.

推荐答案

您需要为每一行添加此脚本。为此,你需要在Gridview的RowDataBound事件中应用它。

如果你搜索谷歌有很多细节。



你可以参考

GridView删除,确认 [ ^ ]
You need to add this script for every row. For this you need to apply this at RowDataBound event of Gridview.
There are a lots details on it if you search google.

You can refer
GridView Delete, with Confirmation[^]

请确保您已编写代码以删除以下内容中的任何行如果阻止



Please make sure your have wrote your codes to delete any row inside the following if block

if(confirm(".....")){
}





当用户按下取消时,这将阻止删除。





此外,如果您可以在此论坛中发布您的代码,那么我将更容易调试此内容。



This will prevent deletion when user press cancel.


Also if you can post your code in this forum so it will be more easy for me to debug this.


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[0].Controls[2]).Attributes["onclick"] = "if(!confirm('Are you sure you want to delete this record?'))return  false;";      
}    
} 
}


这篇关于gridview上的javascript删除链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆