好的所以我在表格中查看了数据,并在本教程中创建了删除选项
http://ricardocovo.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/
但现在我有一个问题如何从正确的行中获取名称来编写类似这样的内容
您真的要删除“产品名称”
答案 0 :(得分:1)
我认为他询问的是ASP.NET MVC,而不是Web表单,因此代码如下所示
视图将是
<table id="table">
<tr>
<td>Id</td>
<td>Name</td>
<td> </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/
看到代码示例希望得到这个帮助。
答案 1 :(得分: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>
答案 2 :(得分:0)
将模型传递给视图并显示名称怎么样? 无法添加评论,抱歉在答案空间发布。 如果您不想传递模型,您可以随时将名称作为参数传递给表视图中的删除功能。
答案 3 :(得分: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>