【转】asp分页,复选框全选,选中的全删
<!--#include file="conn.asp"-->
<%
if request.QueryString("action")="del" then
'Response.Write(request("selectdel"))
conn.execute "delete from shopxp_news where newsid in ("&request("selectdel")&")"
response.Redirect "this.asp"
end if %>
<html>
<head>
<title>Untitled Document</title>
<%
'------------------分页链接函数开始--------------------
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If
Response.Write "<form method=Post action="&filename&">"
Response.Write "<p align='center' class='contents'> "
If CurrentPage<2 Then
Response.Write "<font class='contents'>首页 上一页</font> "
Else
Response.Write "<a href="&filename&"?page=1 class='contents'>首页</a> "
Response.Write "<a href="&filename&"?page="&CurrentPage-1&" class='contents'>上一页</a> "
End If
If n-currentpage<1 Then
Response.Write "<font class='contents'>下一页 尾页</font>"
Else
Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&" class='contents'>"
Response.Write "下一页</a> <a href="&filename&"?page="&n&" class='contents'>尾页</a>"
End If
Response.Write "<font class='contents'> 页次:</font><font class='contents'>"&CurrentPage&"</font><font class='contents'>/"&n&"页</font> "
Response.Write "<font class='contents'> 共有"&totalnumber&"条 "
Response.Write "<font class='contents'>转到:</font><input type='text' name='page' size=2 maxlength=10 class="smallInput" value="¤tpage&">"
Response.Write " <input type='submit' class='contents' value='GO' name='cndok'></form>"
End Function
'------------------分页链接函数结束--------------------
'------------------内容显示函数开始--------------------
sub showContent
dim i
i=0
%>
<table class="tableBorder" width="90%" border="0" align="center" cellpadding="3" cellspacing="1" >
<form name="form1" method="post" action="this.asp?action=del">
<tr>
<td colspan="4" align="center" ><b>文章管理</b></td>
</tr>
<tr >
<td align="center">文章主题</td>
<td align="center">发布人</td>
<td align="center">发布时间</td>
<td align="center">选 择</td>
</tr>
<% do while not rs.eof %>
<tr>
<td style="PADDING-LEFT: 6px"><%=trim(rs("newsname"))%></td>
<td align="center"><%=trim(rs("addname"))%></td>
<td align="center"><%=rs("adddate")%></td>
<td align="center"><input name="selectdel" type="checkbox" id="selectdel" value=<%=rs("newsid")%>></td>
</tr>
<%
i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
rs.close
set rs=nothing
%>
<tr>
<td height="30" colspan="4" align="center">
<input type="submit" name="Submit" value="删除所选文章">全选
<input type="checkbox" name="checkbox" value="Check All" onClick="mm()">
</td>
</tr>
</form>
</table>
<%
End Sub
'------------------内容显示函数结束--------------------
%>
<script language=javascript>
//-------全选按钮触发函数--------
function mm()
{
var a = document.getElementsByTagName("input");
if(a[0].checked==true){
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = false;
}
else
{
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = true;
}
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="100" valign="top">
<%
'--------页面开始---------
Const MaxPerPage=20
dim totalPut
dim CurrentPage
dim TotalPages
dim j
dim sql
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if
set rs=server.createobject("adodb.recordset")
rs.open "select newsid,newsname,addname,adddate from shopxp_news order by adddate desc",conn,1,1
if err.number<>0 then
response.write "数据库中无数据"
end if
if rs.eof And rs.bof then
Response.Write "<p align='center' class='contents'> 您还没有添加文章!</p>"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,"this.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"this.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"this.asp"
end if
end if
end if
'--------页面结束---------
%>
</td>
</tr>
</table>
</body>
</html>
*************************************************************
1、利用rs.move (currentPage-1)*MaxPerPage 方法实现分页,并将分页链接和显示页面内容代码做成函数。
2、通过触发事件实现多个复选框的全选和全不选。
3、对选中的多个复选框所对应内容进行数据库数据删除。
-----------------------------------------
知识点:同名的多个表单项被提交时,此名字对应的值为用逗号分割的各表单项值的组合,并可用数组方式操作。
<%
if request.QueryString("action")="del" then
'Response.Write(request("selectdel"))
conn.execute "delete from shopxp_news where newsid in ("&request("selectdel")&")"
response.Redirect "this.asp"
end if %>
<html>
<head>
<title>Untitled Document</title>
<%
'------------------分页链接函数开始--------------------
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If
Response.Write "<form method=Post action="&filename&">"
Response.Write "<p align='center' class='contents'> "
If CurrentPage<2 Then
Response.Write "<font class='contents'>首页 上一页</font> "
Else
Response.Write "<a href="&filename&"?page=1 class='contents'>首页</a> "
Response.Write "<a href="&filename&"?page="&CurrentPage-1&" class='contents'>上一页</a> "
End If
If n-currentpage<1 Then
Response.Write "<font class='contents'>下一页 尾页</font>"
Else
Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&" class='contents'>"
Response.Write "下一页</a> <a href="&filename&"?page="&n&" class='contents'>尾页</a>"
End If
Response.Write "<font class='contents'> 页次:</font><font class='contents'>"&CurrentPage&"</font><font class='contents'>/"&n&"页</font> "
Response.Write "<font class='contents'> 共有"&totalnumber&"条 "
Response.Write "<font class='contents'>转到:</font><input type='text' name='page' size=2 maxlength=10 class="smallInput" value="¤tpage&">"
Response.Write " <input type='submit' class='contents' value='GO' name='cndok'></form>"
End Function
'------------------分页链接函数结束--------------------
'------------------内容显示函数开始--------------------
sub showContent
dim i
i=0
%>
<table class="tableBorder" width="90%" border="0" align="center" cellpadding="3" cellspacing="1" >
<form name="form1" method="post" action="this.asp?action=del">
<tr>
<td colspan="4" align="center" ><b>文章管理</b></td>
</tr>
<tr >
<td align="center">文章主题</td>
<td align="center">发布人</td>
<td align="center">发布时间</td>
<td align="center">选 择</td>
</tr>
<% do while not rs.eof %>
<tr>
<td style="PADDING-LEFT: 6px"><%=trim(rs("newsname"))%></td>
<td align="center"><%=trim(rs("addname"))%></td>
<td align="center"><%=rs("adddate")%></td>
<td align="center"><input name="selectdel" type="checkbox" id="selectdel" value=<%=rs("newsid")%>></td>
</tr>
<%
i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
rs.close
set rs=nothing
%>
<tr>
<td height="30" colspan="4" align="center">
<input type="submit" name="Submit" value="删除所选文章">全选
<input type="checkbox" name="checkbox" value="Check All" onClick="mm()">
</td>
</tr>
</form>
</table>
<%
End Sub
'------------------内容显示函数结束--------------------
%>
<script language=javascript>
//-------全选按钮触发函数--------
function mm()
{
var a = document.getElementsByTagName("input");
if(a[0].checked==true){
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = false;
}
else
{
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = true;
}
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="100" valign="top">
<%
'--------页面开始---------
Const MaxPerPage=20
dim totalPut
dim CurrentPage
dim TotalPages
dim j
dim sql
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if
set rs=server.createobject("adodb.recordset")
rs.open "select newsid,newsname,addname,adddate from shopxp_news order by adddate desc",conn,1,1
if err.number<>0 then
response.write "数据库中无数据"
end if
if rs.eof And rs.bof then
Response.Write "<p align='center' class='contents'> 您还没有添加文章!</p>"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,"this.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"this.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"this.asp"
end if
end if
end if
'--------页面结束---------
%>
</td>
</tr>
</table>
</body>
</html>
*************************************************************
1、利用rs.move (currentPage-1)*MaxPerPage 方法实现分页,并将分页链接和显示页面内容代码做成函数。
2、通过触发事件实现多个复选框的全选和全不选。
3、对选中的多个复选框所对应内容进行数据库数据删除。
-----------------------------------------
知识点:同名的多个表单项被提交时,此名字对应的值为用逗号分割的各表单项值的组合,并可用数组方式操作。