网学网Ajax编辑为广大网友搜集整理了:asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果绩等信息,祝愿广大网友取得需要的信息,参考学习。
前台代码
复制代码 代码如下:
:<%@ 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("_");
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();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
string sql = "select * from loginuser";
SqlCommand mycom = new SqlCommand(sql, mycon);
mycon.Open();
SqlDataReader myda = mycom.ExecuteReader();
StringBuilder str = new StringBuilder();
str.Append("<table><tr><td><input id=''checkall'' name=''checkall'' type=''checkbox'' onclick=''CheckAll(this)''/>全选</td><td>用户名</td><td>用户全名</td></tr>"