求助一个ASP页面的整合
<!--#include file=conn2.asp-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {font-size: 12px}
.bb {
font-size: 14px;
color: #006699;
text-decoration: underline;
}
.style2 {text-decoration: underline; color: #006699;}
-->
</style></head>
<body>
<%
if session("login")=true then
%>
<table width="59%" height="15" border="0" align="center">
<tr>
<td width="17%" nowrap><div align="center" class="style1">机构编号</div></td>
<td width="49%" nowrap><div align="center" class="style1">机构名称</div></td>
<td width="34%" nowrap><div align="center" class="style1">操作</div></td>
</tr>
<% dim i
i=1
sql="select * from struct"
rs.open sql,conn,1,1
do until rs.eof
if i mod 2 =1 then
%>
<tr bgcolor="#CCFFCC">
<td height="15"><div align="center" class="style1"><%=rs("id")%></div></td>
<td height="15"><a href="../showstruct.asp?id=<%=rs("id")%>"><span class="style1"><%=rs("name")%></span></a></td>
<td height="15"><div align="center" class="style1"><a href="modify.asp?id=<%=rs("id")%>"><span class="style2">修改</span></a>/<a href="do.asp?id=<%=rs("id")&d_type=3 %>"><span class="style2">删除</span></a></div></td>
</tr>
<%
elseif i mod 2 =0 then
%>
<tr bgcolor="#CCCCFF">
<td height="15"><div align="center" class="style1"><%=rs("id")%></div></td>
<td height="15"><a href="../showstruct.asp?id=<%=rs("id")%>"><span class="style1"><%=rs("name")%></span></a></td>
<td height="15"><div align="center" class="style1"><a href="modify.asp?id=<%=rs("id")%>"><span class="style2">修改</span></a>/<a href="do.asp?id=<%=rs("id")&d_type=3 %>"><span class="style2">删除</span></a></div></td>
</tr>
<%
end if
i=i+1
rs.movenext
loop
%>
</table>
</body>
</html>
<%
rs.close
conn.close
else
response.write("<script language=javascript>window.location.href='../login.asp';target='_parent'</script></body></html>")
end if
%>
上面的这些是旧的页面,因为数据太多的缘故,现在我想把下面的这些东西跟上面的整合起来,使页面变成树型结构。
<%
数据库连接
set conn=Server.CreateObject("ADODB.Connection")
conn.open "driver={SQL Server};server=PC-201201311344\SQL2005;DATABASE=wlgj;UID=sa;PWD=123456789"
dim i
i=1
打开所有父层数据
sql="select * from struct where belong='0'"
rs.open sql,conn,1,3
层次数表态变量赋初值
format_i=1
列表主程序段
do while not rs.eof
打印父层数据信息
response.write "<a href=query.asp?class=" & rs("class") & "&belong=" & rs("belong") & ">" & rs("name") & "</a>"
response.write "<br>"
子程序调用,子层数据处理
Call ListSubPower(rs("class"))
rs.movenext
loop
关闭父层数据集
rs.close
set rs=nothing
子层数据处理子程序
Sub ListSubPower(id)
打开隶属于上层 powerid 的所有子层数据信息
set rs_sub=Server.CreateObject("ADODB.Recordset")
rs_sub.Open "select * from struct where belong=" & id & " order by name",conn,1,3
列子层数据
do while not rs_sub.eof
层次数表态变量递进累加
format_i=format_i+1
循环缩进格式控制,因为顶层与二层不需要缩进,所以从第三层开始引用此程序段
for i=format_i to 3 step -1
response.write " |"
response.write " "
next
打印子层数据信息
response.write " |----"
response.write "<a href=query.asp?class=" & rs_sub("class") & "&Belong=" & rs_sub("belong") &">" & rs_sub("name") & "</a>"
response.write "<br>"
递归调用子程序本身,对子层数据进行逐渐处理
ListSubPower(rs_sub("class"))
rs_sub.movenext
loop
层次数表态变量递退累减
format_i=format_i-1
关闭子层数据集
rs_sub.close
set rs_sub=nothing
End Sub
%>
asp 树型结构
[解决办法]
大概猜测你的意思如下:
首先把sql="select * from struct" 改为sql="select * from struct where belong='0'"
然后后面的信息改为
<% dim i
i=1
sql="select * from struct"
rs.open sql,conn,1,1
do until rs.eof
if i mod 2 =1 then
%>
<tr bgcolor="#CCFFCC">
<td height="15"><div align="center" class="style1"><%=rs("id")%></div></td>
<td height="15"><a href="../showstruct.asp?id=<%=rs("id")%>"><span class="style1"><%=rs("name")%></span></a></td>
<td height="15"><div align="center" class="style1"><a href="modify.asp?id=<%=rs("id")%>"><span class="style2">修改</span></a>/<a href="do.asp?id=<%=rs("id")&d_type=3 %>"><span class="style2">删除</span></a></div></td>
</tr>
<%
elseif i mod 2 =0 then
%>
<tr bgcolor="#CCCCFF">
<td height="15"><div align="center" class="style1"><%=rs("id")%></div></td>
<td height="15"><a href="../showstruct.asp?id=<%=rs("id")%>"><span class="style1"><%=rs("name")%></span></a></td>
<td height="15"><div align="center" class="style1"><a href="modify.asp?id=<%=rs("id")%>"><span class="style2">修改</span></a>/<a href="do.asp?id=<%=rs("id")&d_type=3 %>"><span class="style2">删除</span></a></div></td>
</tr>
<%
end if
%>
<%Call ListSubPower(rs("class"))%>
<%
i=i+1
rs.movenext
loop
%>