搜索数据库,无限分类,递归到combobox里。
数据库:
CREATE TABLE [dbo].[sort] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[Sort_Text] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Sort_ParentID] [int] NOT NULL
) ON [PRIMARY]
'递归函数得到select输入框
'调用示例:response.write setComobo(0,9)
'从pid为0开始,id为9的项目为选中
Function setComobo(pid,selectid)
sql = "select * from sort where Sort_ParentID="& pid
call CreateRecordset(scrs,sql)
if scrs.recordcount>0 then
while not scrs.eof
if trim(scrs("Sort_Text"))<>"" then
str = str + "<option value="+CStr(scrs("id"))
if scrs("id")=selectid then
str = str + " selected"
end if
str = str +">"
if scrs("Sort_ParentID") <> 0 then
str = str + "|_"
end if
str = str + scrs("Sort_Text")+"</option>"
str = str + setComobo(scrs("id"),selectid)
end if
scrs.movenext
wend
end if
setComobo = str
End Function
调用:
<select name=""><%
response.write setComobo(0,9)
%></select>
Trackback: http://tb.donews.net/TrackBack.aspx?PostId=69467