网站首页 手机版
 注册 登录
您现在的位置: 畅无忧设计 >> 网络编程 >> ASP教程 >> 正文
最新文章
· FSO 组件asp生成html静态页面碰到缓存
· asp实现长文章自动分页插件
· 在ASP中访问和更新Cookies集合
· ASP错误提示大全
· 学习ASP的几个观点
· ASP用两级联动下拉列表来显示大类和小
· ASP取当前页面地址和参数
· ASP删除记录的同时删除相关图片
· asp将查询结果导出到excel
· ASP批量导入Excel到Access或者Sql Se
热门文章
 化境ASP无组件上传类 - upload_5xs
 一个获取ACCESS数据库表名以及表名
 asp将查询结果导出到excel
 艾恩ASP无组件上传修改版
 ASP批量导入Excel到Access或者Sql 
 ASP读取数据库的Flash+JS图片切换特
 ASP用两级联动下拉列表来显示大类和
 ASP+JS实现网页歌曲连播、点播功能
 使用ASP重启服务器
 asp批量替换access数据库中指定字段
相关文章
ASP不用递归显示无限级分类
asp无限级分类加js收缩伸展功能代码
ASP实现无限级分类
asp无限级显示分类代码
ASP无限级栏目管理代码
来源:百度知道 更新时间:2011/5/14 22:04:07 阅读次数:
字体:[ ] 我要投稿

建一个栏目表,如
栏目ID,栏目名称,父栏目ID,父栏目名称,栏目深度,栏目管理员

用递归可以得出每一级栏目的名称及其父栏目名称。

代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%'if session("login") <> "yes" then response.Redirect "login.asp"%>
<!--#include file="conn.asp"-->
<%
sub popup(str,url)
 response.write "<script language='javascript'>" & chr(13)
 response.write "alert('"&str&"!');" & Chr(13)
 response.write "window.document.location.href='"&url&"';"&Chr(13)
 response.write "</script>" & Chr(13)
 response.End()
end sub
%>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>栏目管理</title>
<link href="admin.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
<!--
function CheckForm()
{
 if (document.form.lan_name.value.length == 0) {
  alert("请输入栏目名称!");
  document.form.lan_name.focus();
  return false;
 }
}
//-->
</script>
<style type="text/css">
<!--
body {
 background-color: #C1D6EA;
}
-->
</style></head>
<%
'递归调用函数,生成一个类别代码
sub reclass(id)
 set rs=server.createobject("adodb.recordset")
 sql="select * from lan where fu_id="&id
 rs.open sql,conn,1,1
 while not rs.eof
  lan_id0  = rs("lan_id")
  lan_name0  = rs("lan_name")
  fu_name0  = rs("fu_name")
  fu_id0   = rs("fu_id")
  level0   = rs("lan_level")
  brstr   = ""
  for j=1 to level0
   brstr="  "&brstr
  next
  'if user_right(session("user_name"),lan_id0)="yes" or session("level")="管理员" then
%>
   <tr class="altbg2" onMouseOver="this.className='altbg1'" onmouseout="this.className='altbg2'">
    <td width="7%" align="center"><%=lan_id0%></td>
    <td width="30%"><%=brstr%>└<%=lan_name0%></td>
    <td width="15%" align="center"><%=fu_name0%></td>
    <td width="23%" align="center"><a href="lanmu_modify.asp?lan_id=<%=lan_id0%>&lan_name=<%=lan_name0%>"><font color="#008000">修改</font></a> <%'if session("level")="管理员" then%><a href="lanmu_admin.asp?lan_id=<%=lan_id0%>&lan_name=<%=lan_name0%>">增加子栏目</a> <a href="lanmu_del.asp?lan_id=<%=lan_id0%>&lan_name=<%=lan_name0%>"><font color="#FF0000">删除</font></a><%'end if%></td>
   </tr>
<%
  'end if
  call reclass(lan_id0)
  rs.movenext
 wend
 rs.close
 set rs=nothing
end sub
%>
<body>
<table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="23%" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="12" colspan="2" bgcolor="#799ae1"></td>
      </tr>
      <tr>
        <td height="25" bgcolor="#1F58C8" class="bt1">    <strong>栏目管理 首页</strong></td>
        <td width="114" bgcolor="#1F58C8"><img src="img/title1.gif" width="114" height="25" /></td>
      </tr>
    </table>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
       
        <tr>
          <td bgcolor="#E4E4E4"> </td>
        </tr>
       
    </table>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
        <tr>
<td>

<!------栏目管理首页,即栏目管理的默认页面------>
<% If request("act") = "" Then %>
<%If request("lan_id")=""  Then%>
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#799AE1">
<form id="form" name="form" method="post" action="lanmu_admin.asp?act=add&fu_name=无" onsubmit="return CheckForm()">
 <tr>
  <td width="100" align="right" bgcolor="#FFFFFF"><strong>栏目名称:</strong></td>
   <td bgcolor="#FFFFFF"><input name="lan_name" type="text" id="lan_name" size="16"></td>
   <td align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="添加一级栏目"></td>
 </tr>
</form>
</table>
<br />
<%end if
If request("lan_id")<>"" then
%>
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#799AE1">
<form id="form" name="form" method="post" action="lanmu_admin.asp?act=add&fu_id=<%=request("lan_id")%>&fu_name=<%=request("lan_name")%>" onsubmit="return CheckForm()">
 <tr>
  <td width="100" align="right" bgcolor="#FFFFFF"><strong>栏目名称:</strong></td>
      <td bgcolor="#FFFFFF"><input name="lan_name" type="text" id="lan_name" size="16"></td>
  <td align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="在【<%=request("lan_name")%>】中添加子栏目"></td>
 </tr>
</form>
</table>
<br />
<%end if%>
<%
set rs1=server.createobject("adodb.recordset")
sql1="select * from lan where fu_id=0 order by lan_id"
rs1.open sql1,conn,1,1
if rs1.eof or rs1.bof then
%>
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#799AE1">
  <tr>
    <td bgcolor="#FFFFFF"><font color="#FF0000">没有栏目</font></td>
  </tr>
</table>
<%else%>
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#799AE1">
  <tr>
    <td width="7%" align="center" bgcolor="#FFFFFF"><strong>栏目ID</strong></td>
    <td width="30%" align="center" bgcolor="#FFFFFF"><strong>栏目名称</strong></td>
    <td width="15%" align="center" bgcolor="#FFFFFF"><strong>父栏目名称</strong></td>
    <td width="23%" align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>

<%
while not rs1.eof
 lan_id1  = rs1("lan_id")
 lan_name1  = rs1("lan_name")
 fu_name1  = rs1("fu_name")
 fu_id1   = rs1("fu_id")
 'if user_right(session("user_name"),lan_id1)="yes" or session("level")="管理员" then
%>
  <tr class="altbg2" onMouseOver="this.className='altbg1'" onmouseout="this.className='altbg2'">
   <td align="center"><%=lan_id1%></td>
   <td><%=lan_name1%></td>
   <td align="center">无</td>
   <td align="center"><a href="lanmu_admin.asp?act=modify&lan_id=<%=lan_id1%>&lan_name=<%=lan_name1%>"><font color="#008000">修改</font></a> <%'if session("level")="管理员" then%><a href="lanmu_admin.asp?lan_id=<%=lan_id1%>&lan_name=<%=lan_name1%>">增加子栏目</a> <a href="lanmu_admin.asp?act=del&lan_id=<%=lan_id1%>&lan_name=<%=lan_name1%>"><font color="#FF0000">删除</font></a><%'end if%></td>
  </tr>
<%
 'end if
 call reclass(lan_id1)
 rs1.movenext
wend
end if
rs1.close
set rs1=nothing
%>
  </table>
<% End If %> 
 
<!------栏目管理--栏目修改页面------>
<% If request("act") = "modify" Then %>
...
<% End If %>

<!--栏目管理--栏目修改保存页面-->
<% If request("act") = "modify_save" Then %>
...
<% End If %>

<!------栏目管理--栏目删除确认页面------>
<% If request("act") = "del" Then %>
...
<% End If %>

<!------栏目管理--栏目删除执行页面------>
<% If request("act") = "del_ok" Then %>
...
<% End If %>

<!--栏目管理--增加新栏目-->
<% If request("act") = "add" Then %>
<%
if request("fu_name")="无" then
 set rs = server.CreateObject("adodb.recordset")
 sql = "select * from lan where lan_name='"&request("lan_name")&"'"
 rs.open sql,conn,3,3
 if not rs.eof then
  call popup("已存在相同栏目名称,请更换",Request.ServerVariables("HTTP_REFERER"))
 else
  rs.addnew
  rs("lan_name") = request("lan_name")
  rs("fu_name") = "无"
  rs("fu_id") = 0
  rs("lan_level") = 0
  rs.update
 
  call popup("栏目添加成功!","lanmu_admin.asp")
 end if
 rs.close
 set rs = nothing
else
 set rs = server.CreateObject("adodb.recordset")
 sql = "select * from lan where lan_name='"&request("lan_name")&"' and fu_name='"&request("fu_name")&"'"
 rs.open sql,conn,3,3
 if not rs.eof then
  call popup("已存在相同栏目名称,请更换",Request.ServerVariables("HTTP_REFERER"))
 else
  set rsa = server.createobject("adodb.recordset")
  sqla = "select * from lan where lan_id = "&request("fu_id")&" and lan_name = '"&request("fu_name")&"'"
  rsa.open sqla,conn,1,1
  rsa_level = rsa("lan_level")
  rsa.close
  set rsa = nothing
 
  rs.addnew
  rs("lan_name") = request("lan_name")
  rs("fu_name") = request("fu_name")
  rs("fu_id") = request("fu_id")
  rs("lan_level") = rsa_level+1
  rs.update
 
  call popup("栏目添加成功!","lanmu_admin.asp")
 end if
 rs.close
 set rs = nothing
end if
%>
<% End If %>

   </td>
  </tr>
      </table>
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td bgcolor="#E4E4E4"> </td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
<%
conn.close
set conn = nothing
%>

  • 上一篇文章:
  • 下一篇文章:
  • 关于我们 - 联系我们 - 广告服务 - 在线投稿 - 友情链接 - 网站地图 - 版权声明
    CopyRight 2008-2010, CWYDESIGN.COM - 畅无忧设计, Inc. All Rights Reserved
    滇ICP备09005765号