用jquery确认对话框替换javascript确认对话框

时间:2015-03-19 20:14:50

标签: c# jquery asp.net

我正在尝试使用两个按钮编写简单的jquery确认对话框:删除和取消。当用javascript编写对话框时,一切运行良好。现在取消按钮工作,但删除按钮不删除任何东西,只是取消删除。我希望commandname调用cmddelete属性,这将删除行。

我正在使用此示例:http://www.codeproject.com/Tips/616118/jQuery-confirmation-in-ASP-NET-GridView

Csharp code:
protected void RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int rowIndex;
            switch (e.CommandName)
            {  
case "CmdDelete":
            rowIndex = (((LinkButton)e.CommandSource).Parent.Parent as GridViewRow).RowIndex;
            DeleteItem(ViewData.List[rowIndex].ID);

Gridview:
<asp:LinkButton ID="btnDelete" runat="server" CommandName="CmdDelete" 
Text="delete"  OnClientClick="javascript:return deleteItem(this.name);" ></asp:LinkButton>  

Javascript代码:

function deleteItem(CmdDelete)) {
    var dialogTitle = 'Message from the webpage';

    $("#deleteConfirmationDialog").html('<p><span class="ui-icon " + 
      "ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>" + 
      "Please click delete to confirm deletion.</p>');

    $("#deleteConfirmationDialog").dialog({
        title: dialogTitle,
        buttons: {
            "Delete": function () { __doPostBack(CmdDelete, ''); 
                      $(this).dialog("close"); },
            "Cancel": function () { $(this).dialog("close"); }
        }
    });


$('#deleteConfirmationDialog').dialog('open');
return false;

}

0 个答案:

没有答案