web窗体:
<script type=\”text/javascript\”>
function del(id) {
$.post(\”Delete.ashx?id=\” + id, function (data) {
if (data == 1) {
$(\”#\” + id).closest(\”tr\”).remove();
}
});
}
</script>
a标签删除:
<a id=\'<%#Eval(\”id\”) %>\’ href=\”#\” οnclick=\’del(<%#Eval(\”id\”) %>)\’>删除</a>
一般处理程序:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = \”text/plain\”;
try
{
var id = context.Request.QueryString[\”id\”];
DataClasses1DataContext linq = new DataClasses1DataContext();
//找到对象
var s = linq.Product.FirstOrDefault(p => p.Id.ToString() == id);
linq.Product.DeleteOnSubmit(s);
linq.SubmitChanges();
context.Response.Write(1); //返回1成功
}
catch (Exception)
{
context.Response.Write(0); //返回0是失败
}
}