【发布时间】:2011-09-06 05:44:38
【问题描述】:
我想问一下如何使用 ajax 绑定来拦截网格的 ajax 删除功能?具体来说,在我点击删除后,当弹出确认提示时,我想根据用户的选择做一些事情,
基本上,如果OK,就做这个,如果CANCEL做那个..
【问题讨论】:
标签: asp.net-mvc-3 telerik telerik-grid telerik-mvc
我想问一下如何使用 ajax 绑定来拦截网格的 ajax 删除功能?具体来说,在我点击删除后,当弹出确认提示时,我想根据用户的选择做一些事情,
基本上,如果OK,就做这个,如果CANCEL做那个..
【问题讨论】:
标签: asp.net-mvc-3 telerik telerik-grid telerik-mvc
您需要使用OnRowDataBound 并将点击处理程序附加到删除按钮。然后您可以显示自定义确认并决定要做什么。如果您想阻止网格删除代码 - 调用 e.stopPropagation()。这是一个简单的示例:
<%: Html.Telerik().Grid(Model)
// Prevent the grid from displaying the default delete confirmation
.Editable(editing => editing.DisplayDeleteConfirmation(false))
// Subscribe to the OnRowDataBound event
.ClientEvents(e => e.OnRowDataBound("onRowDataBound"))
%>
<script>
function onRowDataBound(e) {
$(e.row) // get the current table row (TR) as a jQuery object
.find(".t-grid-delete") // find the delete button in that row
.click(function(e) { // handle its "click" event
if (confirm("Do you want to delete this record?")) {
// User clicked "OK"
} else {
// User clicked "Cancel"
e.stopPropagation(); // prevent the grid deletion code from executing.
}
});
}
</script>
【讨论】:
demo page 似乎包含您正在寻找的示例。
【讨论】: