我如何在删除对话框中实现这一点

JavaScript How Can I achive this in delete dialog

本文关键字:实现 这一点 对话框 删除      更新时间:2023-09-26

好了,现在我有了一个数据表视图我像本教程中那样设置了删除选项

http://ricardocovo.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/

但是现在我有一个问题,我怎样才能从正确的行中得到一个名字来写像这样的东西

你真的要删除"Product Name"吗

我想他问的是ASP。. NET MVC,而不是Web表单,所以代码将如下

视图将为

<table id="table">
<tr>
   <td>Id</td>
   <td>Name</td>
   <td>&nbsp;</td>
</tr>
@foreach(var item in Mode.Items) {
<tr>
   <td>@item.Id</td>
   <td>@item.Name</td>
   <td><button class="deleted-link" value="Delete">delete</button></td>
</tr>
}    
</table>
<div id="delete-dialog" title="Confirmation">
</div>

和视图上的Jquery脚本应该是

$(function(){   
       //alert($('.deleted-link'));
    $('.deleted-link').each(function(){
        $(this).click(function(data){            
            var id = $(this).parent().parent().find('td :first').html();
            $('#delete-dialog').html('<p>Are you sure you want to delete the item with id = {' + id + '} ?</p>');
            $('#delete-dialog').dialog('open');
        });
    });
    $('#delete-dialog').dialog({
        autoOpen: false, width: 400, resizable: false, modal: true, //Dialog options
        buttons: {
            "Continue": function () {          
                $(this).dialog("close");
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });
}); 

您可以在http://jsfiddle.net/SVgEL/

查看代码示例

你可以试试这样做

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ImageButton imb = (ImageButton)e.Row.FindControl("deleteButton");
        string recordName = e.Row.Cells[3].Text;
        imb.OnClientClick = "return confirm('Are You sure Want to Delete the record:-  "+ recordName.ToUpper()+" ? ');";
    }
}

正常点击带有按钮的事件

 <a href="url_to_delete" onclick="return confirm('Are you sure want to delere');">Delete</a>

如何将模型传递给视图并显示名称?不能添加评论,抱歉在这里张贴在回答空间。如果你不想传递模型,你可以将名称作为参数传递给表视图中的delete函数。

假设您已经在使用jQuery,请查看以下内容:

<script type="text/javascript">
    function removeCar(theLink) {
        var theTR = $(theLink).parents('tr');
        var model = $(theTR).children('td._model').html();
        var theConfirm = confirm("Are you sure you want to remove " + model + "?");
        if (theConfirm == true)
            $(theTR).remove();
    }
</script>
<table>
    <thead>
        <tr>
            <th>Make</th>
            <th>Model</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Audi</td>
            <td class="_model">A3</td>
            <td><a href="#" onclick="removeCar(this); return false;">Remove</a></td>
        </tr>
        <tr>
            <td>Audi</td>
            <td class="_model">A4</td>
            <td><a href="#" onclick="removeCar(this); return false;">Remove</a></td>
        </tr>
        <tr>
            <td>Audi</td>
            <td class="_model">A5</td>
            <td><a href="#" onclick="removeCar(this); return false;">Remove</a></td>
        </tr>
    </tbody>
</table>