使用DW用ASP ACCESS编写目录树

2008-02-23 05:57:54来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


  利用ACCESS创建数据库listBase.mdb:

  数据表:listTable

  数据字段:listIdlistNamelistInfoparentId 连接方法:

  <%

  dimsConn,sConnStr,sSql

  sConnStr="DRIVER={MicrosoftAccessDriver(*.mdb)};dbq="&server.mappath("listBase.mdb")

  setsConn=server.createobject("adodb.connection")

  sConn.opensConnStr

  %>

  把以上代码保存成文档:initialize.asp 下面这段程式代码是用来显示目录树用的,保存成文档:inc.asp

  <!--#include file="initialize.asp"-->

  <script language=jscript>

  <!--

  //此函数用来显示和关闭他的子菜单的,并转换其前面的小图片

  function showMenu(menuObj,isSub){

  if(menuObj.style.display=="none"){

  menuObj.style.display="";

  if(isSub==1){

  event.srcElement.src="images/open.gif";

  }

  }

  else{

  menuObj.style.display="none";

  if(isSub==1){

  event.srcElement.src="images/close.gif";

  }

  }

  }

  //-->

  </script>

  <!--下面这段蓝色的区域,是配置目录树的根,其中的内容非数据内的数据,数据库内的数据都附着在他的下面//-->

  <%

  response.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))

  response.write("<tr>" & chr(13)&"<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>")

  response.write("<tr>" & chr(13) & "<td width='18' ><img src='images/root.gif' onclick='jscript:showMenu(subMenu0,0)' style='cursor:hand' alt='不可修改'></td>" & chr(13) & "<td width='100' class='menuPro' id='listName0'>根节点</td>" & chr(13))

  response.write("<td width='40' class='menuFont' align='center' style='cursor:hand' onclick=""jscript:showForm('add',0)"">添加</td>" & chr(13))

  response.write("<td width='40' class='menuFont' align='center' onclick=''></td>" & chr(13))

  response.write("<td>&nbsp;</td></tr></table></td></tr>" & chr(13))

  response.write("<tr id='subMenu0'>" & chr(13) & "<td colspan='2'>" & chr(13))

  '此处调用显示目录树的递归函数

  listChild(0)

  response.write("</td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13))

  '下面代码为显示目录树最关键的函数,使用了递归方法(很多象这样类型的都是用递归来做的。)

  function listChild(id)

  dim sRec,sSql,sNum,sTmp

  set sRec=server.createobject("adodb.recordset")

  sSql="select listId,listName,listInfo,parentId from listTable where parentId=" & id

  sRec.open sSql,sConn,3,1

  if not sRec.eof then

  sNum=1

  response.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))

  while not sRec.eof

  sTmp=sConn.execute("select count(listId) as countSub from listTable where parentId=" & sRec("listId"))

  if sTmp("countSub")>0 then

  response.write("<tr>" & chr(13))

  if sNum=sRec.recordcount then

  response.write("<td width='18' valign='top'><img src='images/angel.gif'></td>" & chr(13))

  else

  response.write("<td width='18' background='images/eline.gif' valign='top'><img src='images/t.gif' ></td>" & chr(13))

  end if

  response.write("<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))

  response.write("<tr>" & chr(13) & "<td width='118' class='menuPro' id='listName" & sRec("listId") & "'><img id='img" & sRec("listId") & "' style='cursor:hand' src='images/close.gif' align='absMiddle' onclick='jscript:showMenu(subMenu" & sRec("listId") & ",1)' alt='" & sRec("listInfo") & "'>" & server.HTMLEncode(sRec("listName")) & "</td>" & chr(13) & "<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('add'," & sRec("listId") & ")"">添加</div></td><td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('edit'," & sRec("listId") & ")"">编辑</div></td>" & chr(13))

  response.write("<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:window.location='disp.asp?disp=del&parentId=" & sRec("listId") & "'"">删除 </div></td>" & chr(13) & "<td>&nbsp;</td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13) & "</td>" & chr(13) & "</tr>" & chr(13))

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: Dreamweaver层的应用

下一篇: 用Dreamweaver制作拖拽效果