首页 > 开发 > AJAX > 正文

asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果

2024-09-01 08:29:26
字体:
来源:转载
供稿:网友
前台代码 代码如下:
:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>用户信息操作</title>
<script language="javascript" type="text/javascript" src="ajax/jquery.js"></script>
<script language="javascript" type="text/javascript">
//页面的初始化
$(document).ready( function(){ loadUserInfo(); });
//加载用户信息到页面
function loadUserInfo()
{
$.ajax(
{
type:"POST",
url:"Default.aspx",
data:{action:'action'},
success:loadUserInfoCallbace
}
);
}
//页面初始化回调函数
function loadUserInfoCallbace(r)
{
if(r=="")
{
$("#userInfo").html("暂无数据");
}
else
{
$("#userInfo").html(r);
}
}
//全部选中
function CheckAll(obj)
{
$("input[@type=checkbox][@name=checkItem]").attr("checked",$(obj).attr("checked"));
}
//收集所有选中项
function NumberID()
{
var allcheckboxs=$("input[@type=checkbox][@name=checkItem][checked]");
var ids="";
for(i=0;i<allcheckboxs.length;i++)
{
var id=$(allcheckboxs[i]).attr("id").split("_")[1];
ids+=id;
ids+=",";
}
return ids;
}
//删除用户
function DeleteUser()
{
if(!window.confirm("您真的要删除选中用户信息吗?"))
{
return;
}
var ids=NumberID();
$.ajax({
type:'POST',
url:'Default.aspx',
data:{action:'Delete',userid:ids},
success:deleteUserCall
});
}
//删除用户回调函数
function deleteUserCall(r)
{
if(r=="ok")
{
alert("删除成功");
loadUserInfo();
}
else
{
alert("失败");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center" id="userInfo">
</div>
</form>
</body>
</html>

后台代码:
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
string Straction = "";
protected void Page_Load(object sender, EventArgs e)
{
Straction = Request["action"];
if(Straction=="action")
{
UserInfo();
}
if (Straction == "Delete")
{
DeleteUser();
}
}
/// <summary>
/// 周昕 2009-6-8号加载用户详细信息
/// </summary>
public void UserInfo()
{
SqlConnection mycon = new SqlConnection();
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表