<asp:CommandField ShowDeleteButton="True" />
如何鏈接一個簡單的jQuery的方法來刪除按鈕,只是要求用戶確認並返回(true或false),如果用戶確信他想要刪除記錄在GridView控件或不?刪除的GridView行與jQuery
<asp:CommandField ShowDeleteButton="True" />
如何鏈接一個簡單的jQuery的方法來刪除按鈕,只是要求用戶確認並返回(true或false),如果用戶確信他想要刪除記錄在GridView控件或不?刪除的GridView行與jQuery
您捕獲該網格視圖的刪除按鈕,並添加一個確認。另外你還要注意不要覆蓋現有的命令。
jQuery(document).ready(function()
{
// note: the `Delete` is case sensitive and is the title of the button
var DeleteButtons = jQuery('#<%= GridViewName.ClientID %> :button[value=Delete]');
DeleteButtons.each(function() {
var onclick = jQuery(this).attr('onclick');
jQuery(this).attr('onclick', null).click(function() {
if (confirm("Delete this record? This action cannot be undone...")) {
return onclick();
}
else
{
return false;
}
});
});
});
如果你把一個UpdatePanel內的GridView控件,那麼你需要使用pageLoad()
進行更新(版本4+)爲:pageLoad()
是在頁面加載運行
function pageLoad()
{
var DeleteButtons = jQuery('#<%= GridViewName.ClientID %> :button[value=Delete]');
DeleteButtons.each(function() {
var onclick = jQuery(this).attr('onclick');
jQuery(this).attr('onclick', null).click(function() {
if (confirm("Delete this record? This action cannot be undone...")) {
return onclick();
}
else
{
return false;
}
});
});
}
,同時也對UpdatePanel中的每個ajax更新。
使用確認框.. – Scorpio