このようなイメージボタンを使用して、グリッドビューで行を削除しようとしています
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" CssClass="gridColumnDelete" runat="server" ImageUrl="~/Imgs/Delete.png" AlternateText="Delete"
CommandName="Delete" CommandArgument="<%#((GridViewRow)Container).RowIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
こんな感じで削除確認用のjQueryダイアログを書いてみました
$(document).ready(function () {
confirm();
});
function confirm() {
$(".gridColumnDelete").click(function () {
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Yes": function () {
__doPostBack();
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
});
return false;
}
ダイアログに使用するdivタグはこちら
<div id="dialog-confirm" title="Confirm?" style="display:none">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure to delete the trip?</p>
</div>
問題は、[はい] をクリックするか、ダイアログでキャンセルするかどうかです。Gridview_RowCommand は c# で実行されます。
実際、確認ダイアログのボタンをクリックする前でも、Gridview_RowCommand が実行されます。