前台代码复制代码 代码如下:
:<%@ 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="/UploadFiles/2021-04-02/jquery.js"><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();
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>");
while (myda.Read())
{
str.Append("<tr><td>");
str.Append("<input id='checkItem_" + myda["ID"].ToString() + "' type='checkbox' name='checkItem' style='text-align='left' onclick=' NumberID()'/></td>");
str.Append("<td>" + myda["UserName"].ToString() + "</td>");
str.Append("<td>" + myda["FullName"].ToString() + "</td></tr>");
}
str.Append("</table>");
str.Append(" <div style=' text-align:center'><input type='button' value='删除' onclick='DeleteUser()' /></div>");
Response.Clear();
Response.ContentType = "application/text";
Response.Write(str);
Response.End();
}
/// <summary>
/// 周昕 2009-6-8 删除选中用户的详细信息
/// </summary>
public void DeleteUser()
{
//获取用户ID
string strID = Request["userid"];
string Userid = strID.Substring(0, strID.Length - 1);
//转换成为数组
string[] stridArray = Userid.Trim().Split(',');
string sql = "delete from loginuser where ID='" + stridArray[0].ToString() + "'";
for (int i = 0; i < stridArray.Length; i++)
{
string id = stridArray[i].ToString();
sql += "or ID='" + id + "'";
}
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
mycon.Open();
SqlCommand mycom = new SqlCommand(sql, mycon);
int n = (int)mycom.ExecuteNonQuery();
mycon.Close();
if (n > 0)
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("ok");
Response.End();
}
else
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("no");
Response.End();
}
}
}
效果图:
:<%@ 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="/UploadFiles/2021-04-02/jquery.js"><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();
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>");
while (myda.Read())
{
str.Append("<tr><td>");
str.Append("<input id='checkItem_" + myda["ID"].ToString() + "' type='checkbox' name='checkItem' style='text-align='left' onclick=' NumberID()'/></td>");
str.Append("<td>" + myda["UserName"].ToString() + "</td>");
str.Append("<td>" + myda["FullName"].ToString() + "</td></tr>");
}
str.Append("</table>");
str.Append(" <div style=' text-align:center'><input type='button' value='删除' onclick='DeleteUser()' /></div>");
Response.Clear();
Response.ContentType = "application/text";
Response.Write(str);
Response.End();
}
/// <summary>
/// 周昕 2009-6-8 删除选中用户的详细信息
/// </summary>
public void DeleteUser()
{
//获取用户ID
string strID = Request["userid"];
string Userid = strID.Substring(0, strID.Length - 1);
//转换成为数组
string[] stridArray = Userid.Trim().Split(',');
string sql = "delete from loginuser where ID='" + stridArray[0].ToString() + "'";
for (int i = 0; i < stridArray.Length; i++)
{
string id = stridArray[i].ToString();
sql += "or ID='" + id + "'";
}
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
mycon.Open();
SqlCommand mycom = new SqlCommand(sql, mycon);
int n = (int)mycom.ExecuteNonQuery();
mycon.Close();
if (n > 0)
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("ok");
Response.End();
}
else
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("no");
Response.End();
}
}
}
效果图:
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。