分页显示中多选删除数据的问题

firefly_xu 2003-10-17 09:38:22
<%
分页显示程序
...
<%do while not rst.eof and rowcount>0%>
...
<td width="6%" align="center"><font font face="宋体" size="2" color="#000080"><%=rst("cname")%></td>
<td width="6%" align="center" ><font font face="宋体" size="2" color="#000080"><input type="checkbox" name="delok" value="<%=rst("ID")%>"></a></td>
...
<%
rowcount=rowcount-1
rst.movenext
loop
%>
<input type="button" value="删除选定记录" name="butt2">


我希望通过这个程序实现:在显示的记录中选择要删除的记录(多选),
点击“删除选定记录”按钮,将这些选定的记录一并删除。
我不知道如何实现这些功能:这些checkbox的value怎么提交给删除程序。
删除程序怎么确定要删除的checkbox value的个数、、、
请高手指导,满意必给分,谢谢!
...全文
139 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
Miriamy 2003-10-19
  • 打赏
  • 举报
回复
//function.js

function CheckAll(){
var i=0;
var arrayCheckbox = document.getElementsByName("checkbox")
for(i=0;i<arrayCheckbox.length;i++){
arrayCheckbox[i].checked=true;
}
}

function CheckOther(){
var i=0;
var arrayCheckbox = document.getElementsByName("checkbox")
for(i=0;i<arrayCheckbox.length;i++){
arrayCheckbox[i].checked=false;
}
}
///////////////////////////////////////////
提交页

html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form>
<input type="checkbox" name="checkbox" value="c1">
<input type="checkbox" name="checkbox" value=" c2">
<input type="button" name="Button" value="全选" onClick="CheckAll();">
<input type="button" name="Button" value="反选" onClick="CheckOther();">
<input type="submit" name="Button" value="提交">
</form>
</body>
</html>
///////////////////////////////////////////////////////////
执行页

conn.execute("delete from 表 where id in ("& request.form("checkbox")&")")

imlogo 2003-10-17
  • 打赏
  • 举报
回复
我也想知道如何删除跨页信息

就是说被删除的信息可能分处于多个页面中,楼上说用客户端脚本的朋友,能不能贴一点代码?
lovehwq21 2003-10-17
  • 打赏
  • 举报
回复
晕,给了这么多还不够啊,不试不行啊,楼主
firefly_xu 2003-10-17
  • 打赏
  • 举报
回复
To:wanghui0380(放歌) ( )
是不是把
...
2.dellist=replace("request("xxx"),", ",",")
3.conn.execute("delete from art where id in dellist")
...
写入另一个ASP程序,比方“del.asp“里
然后本分页程序的
<input type="button" value="删除选定记录" name="butt2"
onclick=formcompany.method="post":formcompany.action="del.asp":formcompany.submit
language="vbscript">
这样进行提交呢?
不能用“<form name="formdel" method="post" action="del.asp">”
因为分页程序的此处要提交分页的信息。
firefly_xu 2003-10-17
  • 打赏
  • 举报
回复
To:socamp(camp-lai)
如果是后者,定义Session数组时你怎么确定数组的个数呢?
  • 打赏
  • 举报
回复
是只删除一页内的多选记录还是用户在浏览很多页后一并提交然后删除多页的多选记录?
如果是后者,建议用两Session数组来保存,一个保存数据,另一个保存顺序(如:1,3,5)。
avonqin 2003-10-17
  • 打赏
  • 举报
回复
晕~~~
tigerwen01(小虎)(编程艺术化) 的就可以啦,你还有什么问题?
wanghui0380 2003-10-17
  • 打赏
  • 举报
回复
一个就可以了
firefly_xu 2003-10-17
  • 打赏
  • 举报
回复
To:wanghui0380(放歌) ( )
我的分页程序,每页显示10条记录
2.dellist=replace("request("xxx"),", ",",")语句的", "部分是不是也要10个呢?
firefly_xu 2003-10-17
  • 打赏
  • 举报
回复
to:lp1983(拼) ( )
确实只能删除本页显示的数据。
可我不知道怎么使用客户端的脚本分页显示数据库内的数据。请指教。
firefly_xu 2003-10-17
  • 打赏
  • 举报
回复
是不是把
...
2.dellist=replace("request("xxx"),", ",",")
3.conn.execute("delete from art where id in dellist")
...
写入另一个ASP程序,比方“del.asp“里
然后本分页程序的
<input type="button" value="删除选定记录" name="butt2"
onclick=formcompany.method="post":formcompany.action="del.asp":formcompany.submit
language="vbscript">
这样进行提交呢?
tigerwen01 2003-10-17
  • 打赏
  • 举报
回复
使用For Each ... in ...循环,下面给出一个例程:
seldel.asp:
<form method="post" action="del.asp">
<%do while not rs.eof%>
<tr>
<td>
<input type=checkbox name="xxx" value=<%=rs("id")%>><%=rs("field")%>
</td>
</tr>
<%
rs.MoveNext
loop
%>
<input type=submit name=s1 value=删除>
</form>
----------------------
del.asp:
<%
...
dim articalID,strArticalID
strArticalID=""
For Each strArticalID in Request.Form("xxx")
articalID=Cint(strArticalID)
if strArticalID <> "" then
Conn.execute "delete from table where id="&Cstr(articalID)
strArticalID=""
end if
next
Response.write "数据删除成功!"
%>
lp1983 2003-10-17
  • 打赏
  • 举报
回复
不会的,名字一样会被认为成一个数组的
ttt2 2003-10-17
  • 打赏
  • 举报
回复
<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<link rel="stylesheet" type="text/css" href="../../main.css">
</head>
<!-- #include file="../../net.asp" -->
<!-- #include file="../../bl.asp" -->
<!-- #include file="../../check.asp" -->

<%
if checkqx(session("sofficeqx"),13)=false then
response.write "您没有权限!"
response.end
end if

%>
<%zgqx=checkqx(session("sofficeqx"),13)%>
<body>
<script language="javascript">
function check()
{
if (confirm('<%=msgdelok%>'))
{
document.form1.submit()
}

}
</script>
<%
delid=request.form("delid")
if delid="" then

gjz=request.querystring("gjz")

p=request.querystring("p")
if p="" then p=1
set rs=server.createobject("adodb.recordset")
rs.pagesize=session("sofficesize")
if gjz="" then
rs.open "select * from work where mk=2 order by id desc",cn,1,3
else
rs.open "select * from work where mk=2 and title like '%"&gjz&"%' order by id desc",cn,1,3
end if
%>
<p>当前位置:标准规范   当前共有<b><%=rs.recordcount%></b>篇文档   </p> <form method="get" action="doclist.asp" name="form2">
<table border="0" width="100%">
<tr>
<td width="33%">
<input type="button" value="增加记录" class=in02 onclick="location.href='adddoc.asp'" <%if zgqx=false then%>disabled<%end if%>>
<input type="button" value="删除记录" class=in02 onclick="check()" <%if zgqx=false then%>disabled<%end if%>>
</td>
<td width="67%">
<p>关键字 <input type="text" name="gjz" size="20" class="in01" value="<%=gjz%>"> <input type="submit" value="查找" name="B1" class="in02"></p>
</td>
</tr>
</table> </form>
<form name="form1" method="post" action="doclist.asp">
<table border="1" width="100%" bordercolordark="#FFFFFF" cellspacing="0" cellpadding="0" bordercolorlight="#C0C0C0" frame="box">
<tr>
<td width="10%" height="18" bgcolor="#F2F2F2">
<p align="center">记录编号</td>
<td width="21%" height="18" bgcolor="#F2F2F2">
文号</td>
<td width="35%" height="18" bgcolor="#F2F2F2">标准规范名称</td>
<td width="17%" height="18" bgcolor="#F2F2F2" align="center">查看</td>
<td width="17%" height="18" bgcolor="#F2F2F2" align="center">时间</td>
</tr>
<%
if not rs.eof then
i=0
rs.absolutepage=cint(p)
end if
while not rs.eof and i<rs.pagesize%>
<tr onmouseover="this.style.backgroundColor='#F2F2F2';this.style.cursor='hand'" onmouseout="this.style.backgroundColor='#ffffff'">
<td width="10%" height="19"><input type="checkbox" name="delid" value="<%=rs("id")%>"><%=rs("id")%></td>
<td width="21%" height="19"> <%=rs("wh")%></td>
<td width="35%" height="19"> <a href="modidoc.asp?id=<%=rs("id")%>"><%=rs("title")%></a></td>
<td width="17%" height="19">
<p align="center"><a href="look.asp?id=<%=rs("id")%>">查看</a></p>
</td>
<td width="17%" height="19"> <%=rs("adate")%></td>
</tr>
<%
i=i+1
rs.movenext
wend%>
</table><Br>  共有<%=rs.recordcount%>条记录    每页显示<%=rs.pagesize%>条     <% if rs.pagecount=0 then%>0<%else%><%=p%><%end if%> / <%=rs.pagecount%>   <%
if rs.recordcount=0 then
else
%><input type="button" value="首页" onclick="location.href='doclist.asp?gjz=<%=gjz%>&bmid=<%=bmid%>&bmname=<%=bmname%>'" class=in02>
<%if cint(p)>1 then%>
<input type="button" value="上页" onclick="location.href='doclist.asp?p=<%=p-1%>&gjz=<%=gjz%>&bmid=<%=bmid%>&bmname=<%=bmname%>'" class=in02>

<%end if%>
<% if cint(p)-rs.pagecount=0 then%>
<%else%>
<input type="button" value="下页" onclick="location.href='doclist.asp?p=<%=p+1%>&gjz=<%=gjz%>&bmid=<%=bmid%>&bmname=<%=bmname%>'" class=in02>
<%end if%>
<input type="button" value="尾页" onclick="location.href='doclist.asp?p=<%=rs.pagecount%>&gjz=<%=gjz%>&bmid=<%=bmid%>&bmname=<%=bmname%>'" class=in02>
<%end if%>
<input type="hidden" value="<%=p%>" name="p">
</form>
<%
else
p=request.form("p")
sql="delete from work where id in ("&delid&")"
'response.write sql
cn.execute sql
response.redirect "doclist.asp?p="&p
end if
%>
</body>

</html>
lp1983 2003-10-17
  • 打赏
  • 举报
回复
如果你使用的是服务器端的分页的话,只能删除当前页的选中的内容,因为你选择其他页时,页面会提交,这样你选中的内容在下页提交时已经不存在了,建议使用客户端的脚本分页,这样不会提交,如果你只是想要当前页的删除,那么直接在处理页面request("delok")不就可以了吗
firefly_xu 2003-10-17
  • 打赏
  • 举报
回复
这里所有checkbox名都为"delok"对程序不会有影响吗?
wanghui0380 2003-10-17
  • 打赏
  • 举报
回复
1.给你的checkbox名成同一个名字如:xxx
2.dellist=replace("request("xxx"),", ",",")
3.conn.execute("delete from art where id in dellist")
这样就可以了

注:同名的checkbox传的植类似如下格式12213, 21331, 123123, 1344他是以", "为分隔的,注意逗号后还有一个空格
mjwgtm 2003-10-17
  • 打赏
  • 举报
回复
<%
for i=1 to request.form("idd").count
conn.execute("delete from art where id="&request.form("idd")(i)) //idd为checkbox名
next
%>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧