<script type="text/javascript">
jQuery(document).ready(function () {
// note: the `Delete` is case sensitive and is the title of the button
var DeleteButtons = jQuery('#<%= gvShoppingCart.ClientID %> :button[value=Delete]');
DeleteButtons.each(function () {
var onclick = jQuery(this).attr('onclick');
jQuery(this).attr('onclick', null).click(function () {
if (confirm("Are you sure you want to delete item from shopping cart?")) {
return onclick();
}
else {
return false;
}
});
});
});
</script>
如果为true(而不是onclick()),我如何更改上面的代码以返回下面的方法
protected void gvShoppingCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//code here
}
编辑:下面的新代码 -
<script type="text/javascript">
jQuery(document).ready(function () {
$('.deleteStyle').click(function () {
return confirm("Are you sure you want to delete");
});
});
</script>
<style type="text/css">
.deleteStyle
{
}
</style>
网格视图删除:
<asp:CommandField ControlStyle-CssClass="deleteStyle" ShowDeleteButton="True" ButtonType="Button" />
gvRoles_RowDeleting(注意我现在在 Roles Gridview 上测试它!)
protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
BusinessLayer.Roles rls = new BusinessLayer.Roles();
rls.deleteRole(rls.getRole(gvRoles.DataKeys[e.RowIndex].Value.ToString()));
this.BindRoles();
}