当前位置: 首页 > 图文教程 > 网络编程 > ASP > 针对select写了一个通用的option输出函数

ASP
深入研究Application和Session对象(2)
深入研究Application和Session对象(3)
开始 .Net的旅程(一)
开始 .Net的旅程(二)
手把手教你使用VB来创建ASP组件(1)
手把手教你使用VB来创建ASP组件(2)
手把手教你使用VB来创建ASP组件(3)
手把手教你使用VB来创建ASP组件(4)
手把手教你使用VB来创建ASP组件(5)
手把手教你使用VB来创建ASP组件(6)
手把手教你使用VB来创建ASP组件(7)
手把手教你使用Java来编写ASP组件(1)
手把手教你使用Java来编写ASP组件(2)
手把手教你使用Java来编写ASP组件(3)
手把手教你使用Java来编写ASP组件(4)
手把手教你使用Java来编写ASP组件(5)
手把手教你使用Java来编写ASP组件(6)
ASP 3.0高级编程(二十四)
ASP 3.0高级编程(二十五)
ASP 3.0高级编程(二十六)

ASP 中的 针对select写了一个通用的option输出函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 50 ::
收藏到网摘: n/a

 

function writeSlt(arrstr,arrstrValue,selectedstr)
'arrstr 要显示在option里面的值,arrstrValue option的实际值,selectedstr要选中的默认值
'将一个字串分割为数组,输出select的option,并选中selectedstr arrstr&arrstrValue长度要一致
arr=split(arrstr,",")
arrValue=split(arrstrValue,",")
j=0
do while j<=ubound(arr)
 if trim(arrValue(j))=trim(selectedstr) then
  response.write "<option value='" & arrValue(j) & "' selected>" & arr(j) & "</option>"
 else
  response.write "<option value='" & arrValue(j) & "'>" & arr(j) & "</option>"
 end if
 j=j+1
loop
end function

 

可以从数据库中读出数据,形成逗开分隔的字符串,来动态生成select的<option>

function getArrString(table,fld,cond,sortfld)
'获取一个指定表中指定字段指字条件的数据,返回一个以逗号分隔的字符串
set rs=server.createobject("adodb.recordset")
sql="select " & fld & " from " & table
if len(cond)>0 then
 sql=sql & " where " & cond
end if
if len(sortfld)>0 then
 sql=sql & " order by " & sortfld
end if
rs.Open sql,conn,1,1
if not (rs.bof or rs.EOF) then
 do while not rs.EOF
  getArrString=getArrString & trim(rs(fld)) & ","
  rs.MoveNext
 loop
end if
getArrString=left(getArrString,len(getArrString)-1)
rs.Close
set rs=nothing
end function