C# JavaScript如何在删除对话框中实现这一点
好的,我有一个表中数据的视图,我在本教程中做了删除选项 但是现在我有一个问题,我怎么能从正确的行中得到一个名字来写这样的东西呢C# JavaScript如何在删除对话框中实现这一点,c#,javascript,asp.net-mvc,C#,Javascript,Asp.net Mvc,好的,我有一个表中数据的视图,我在本教程中做了删除选项 但是现在我有一个问题,我怎么能从正确的行中得到一个名字来写这样的东西呢 是否确实要删除“产品名称”您可以尝试以下操作 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ImageButton imb
是否确实要删除“产品名称”您可以尝试以下操作
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>
功能删除卡(链接){
var theTR=$(theLink.parents('tr');
var model=$(theTR).children('td._model').html();
var theConfirm=confirm(“您确定要删除“+model+”?”);
如果(确认==真)
$(theTR.remove();
}
制作
模型
奥迪
A3
奥迪
A4
奥迪
A5
我想他问的是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>
身份证件
名称
@foreach(模式中的var项。项){
@项目Id
@项目名称
删除
}
视图上的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");
}
}
});
});
$(函数(){
//警报($('.deleted link'));
$('.deleted link')。每个(函数(){
$(此)。单击(函数(数据){
var id=$(this.parent().parent().find('td:first').html();
$(“#删除对话框”).html(“是否确实要删除id={'+id+'}的项目?”);
$(“#删除对话框”)。对话框(“打开”);
});
});
$(“#删除对话框”)。对话框({
自动打开:false,宽度:400,可调整大小:false,模式:true,//对话框选项
按钮:{
“Continue”:函数(){
$(此).dialog(“关闭”);
},
“取消”:函数(){
$(此).dialog(“关闭”);
}
}
});
});
您可以在中看到代码示例
希望获得此帮助。在客户端单击“返回确认”(“您确定要删除吗”);“是否有不带GridView的选项?此答案适用于WebForms。我相信OP使用的是ASP.NETMVC。然后你需要在客户端连接事件,它实际上不是一个Web表单,伙计。