怎么样通过asp编写连接数据库的select下拉框函数?
<%'objectname select控件名称,strsql 数据库查询语句,str_value数据库关键字字段名,str_text在下拉框中显示的内容字段名,str_ifvalue 提交的初值关键字,int_text,int_value 当没有对应记录时,下拉框显示的值和关键字'************************有初值的*************************************
sub object_select(objectname,strsql,str_value,str_text,str_ifvalue,int_text,int_value)
dim resbuff
%><select name="<%=objectname%>">
<%if int_text<>"" then%>
<option value="<%=int_value%>"><%=int_text%></option>
<%end if%>
<%
set resbuff=server.CreateObject("adodb.recordset")
resbuff.open strsql,conn,1,1
if err.number <> 0 then
response.write "数据库操作失败:"&err.description
response.redirect"error.htm"
else
if not resbuff.eof and not resbuff.bof then
resbuff.movefirst
do while not resbuff.eof
if resbuff(str_value)=str_ifvalue then
%><option value="<%= resbuff(str_value)%>" selected><%=resbuff(str_text)%></option><%
else
%><option value="<%= resbuff(str_value)%>"><%=resbuff(str_text)%></option><%
end if
resbuff.movenext
loop
end if
end if
set resbuff=nothing
%></select><%
end sub
本文地址:http://www.45fan.com/a/question/71169.html