(水水)Eddie's blog

---------勿在浮沙筑高台
文章 - 95,收藏 - , 评论 - 185, trackbacks - 2

搜索数据库,无限分类,递归到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


[点击此处收藏本文]  发表于2004年08月16日 11:54 AM




正在读取评论……

发表评论

大名
网址
验证码
评论