我如何在删除对话框中实现这一点
JavaScript How Can I achive this in delete dialog
好了,现在我有了一个数据表视图我像本教程中那样设置了删除选项
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> </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>
相关文章:
- 如何做到这一点,使代码在不传递条件后执行函数
- gmap3如何做到这一点-它显示圆圈的任何事件
- AngularJS:有没有比指定的方法更好的方法来实现这一点
- config.fullPage = true;在 ckEditor 内联模式下无法正常工作.如何实现这一点
- 如何在Jquery中实现这一点?(JS到Jquery)
- 为什么我不能将 Backbone.Collection 用作通用集合?有没有实现可以做到这一点
- JavaScript 函数调用计时.实现这一点的最佳方法
- 偏移顶部如何实现这一点
- 我怎样才能通过编程实现这一点
- 我可以'如果语句在Javascript:S中有效,则似乎不会实现这一点
- 需要在服务器中发送数据和访问数据的帮助.我想使用JavaScript(nodejs)来实现这一点
- 如何用jquery实现这一点
- 我该如何在mustache.js中实现这一点
- 我如何在删除对话框中实现这一点
- 如何在Javascript, jQuery或Angular中实现这一点
- 实现这一点.值在javascript的多元素事件监听器上下文中
- 我如何使用承诺(Q包)实现这一点
- 我如何使用 gulp 来实现这一点
- 每当我的页面加载,我希望文本框是空的.如何使用javascript实现这一点
- 如何在不使用jQuery刷新页面的情况下实现这一点