1、如果要实现无刷新就不能使用ASP.NET控件,要使用HTML。
前台代码:
<a href="javascript:void(0)" class="delete" id='<%# Eval("Id") %>'>删除</a>
2、创建一般处理程序
public void ProcessRequest(HttpContext context)
{
var id = Convert.ToInt32(context.Request.QueryString["id"]);
var del = ProductManage.Delete(id);
context.Response.ContentType = "application/json";
context.Response.Write(del);
}
3、js代码
<script type="text/javascript">
$(function() {
//为每个按钮添加一个单击事件
$(".delete").click(function() {
//弹出确认删除对话框
if (confirm("确定删除吗?")) {
var $this = $(this);
//获取要删除的行
var id = $this.attr("id");
$.post("delete.ashx?id="+id, function(data) {
if (data>0) {
//移除选中行
$this.closest("tr").remove();
alert("删除成功");
}
});
}
});
})
</script>