函数代码:
<% '参数LeftText可以很方便的区分父栏目与子栏目之间的'错位'关系 Function SelectList(ID, LeftText) Dim Rs, Sql, ChildCount Set Rs = Server.CreateObject("Adodb.Recordset") Sql = "Select ID,ColumnName from Column where ParentID = " & ID & " " '起始栏目 Sql = Sql & "Order by ID ASC" Rs.Open Sql, Conn, 1, 1 Do While Not Rs.EOF ChildCount = Conn.Execute("Select Count(*) from Column where ParentID = " & Rs(0))(0) '子栏目数量 Response.Write("<option value=""" & Rs(0) & """>" & LeftText & Rs(1) & "</option>" & vbCrLf) If ChildCount > 0 Then Call SelectList(Rs(0), LeftText & " ┣ ") '递归 Rs.MoveNext Loop Rs.Close Set Rs = Nothing End Function %>
调用方法:
<% Response.Write("<select name=""SortID"" id=""SortID"">" & vbCrLf) Call SelectList(0, "") Response.Write("</select>" & vbCrLf) %>