0

このようなイメージボタンを使用して、グリッドビューで行を削除しようとしています

                        <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 が実行されます。

4

3 に答える 3

1

最後に return ステートメントを削除し、以下のようにします

"Yes": function () {
   // __doPostBack(); 
    $(this).dialog("close");
    return true;
},
"Cancel": function () {
    $(this).dialog("close");
    return false;
}

そして、以下のように変更asp:ImageButtonします

<asp:ImageButton ID="imgDelete"  OnClientClick="return confirm();" CssClass="gridColumnDelete" runat="server" ImageUrl="~/Imgs/Delete.png" AlternateText="Delete"  
                            CommandName="Delete" CommandArgument="<%#((GridViewRow)Container).RowIndex %>"/>
于 2013-10-17T03:11:22.410 に答える