0

好的,所以我查看了表中的数据,并在本教程中设置了删除选项

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

但是现在我有一个问题我如何从正确的行中获取名称来写这样的东西

你真的要删除“产品名称”吗

4

4 回答 4

1

我想他问的是 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/看到代码示例

希望这有帮助。

于 2013-05-20T13:09:45.937 回答
0

你可以试试像这样

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>
于 2013-05-20T12:32:09.037 回答
0

将模型传递给视图并显示名称怎么样?无法添加评论,抱歉在答案空间中发布。如果您不想传递模型,您总是可以将名称作为参数传递给表视图中的删除函数。

于 2013-05-20T12:41:41.173 回答
0

假设您已经在使用 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>
于 2013-05-20T12:47:13.413 回答