asp中加载下拉列表框初始值

来源:互联网 发布:怎么网络监听 编辑:程序博客网 时间:2024/05/17 20:30
       以前经常用asp.net写东西,最近因为工作原因需要修改一个asp程序,其中遇到的一个问题是将下拉列表框中的任意一个值,设置为默认值。而一般都是第一个是被选择的。如果是其他的,那么就需要你去编程了。下面是我写的测试代码如下:
<!--#include file="conn.asp"--><%On Error Resume nextresponse.charset="GB2312"session.codepage=936%><head><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /><title>test</title></head><body><form name="form1" method=post><h1>test</h1><select  name="my_t" ><option>1</option>    <option>2</option>    <option>3</option></select><select name="c" style="height:18px;" ><%set rs=conn.execute("select distinct p_sort as mysort from 56770_pro_log ")        if not rs.eof then           do while not rs.eof   var  bol_add_item=0      if  Trim(rs("mysort")) ="感冒药" then     bol_add_item = 1  %>  <option value="<%=Trim(rs("mysort"))%>" selected><%=rs("mysort")%></option>  <%else  %><option value="<%=Trim(rs("mysort"))%>"><%=rs("mysort")%></option>  <%end ifrs.movenextloop end if            rs.close:set rs=nothing         %>          <% if  bol_add_item = 0 then %>          <option selected value="">--请选择--</option>          <% end if %>  </select></form>      </body></html>====================
下面的部分代码是,我正式程序中应用到的代码:
<select name="p_sort1" onChange="(document.form1.p_sort.value=this.options[this.selectedIndex].value)"><%set rsa=server.CreateObject("adodb.recordset")rsa.open "select * from 56770_sort order by s_paixu desc", conn, 1, 1if rsa.eof and rsa.bof thenresponse.write "还没有数据,请添加!"elsebol_add_item=0        do while not rsa.eofif rsa("s_name") = rs("p_sort") then bol_add_item=1 %><option value="<%=rsa("s_name")%>" selected><%=rsa("s_name")%></option><%else%><option value="<%=rsa("s_name")%>"><%=rsa("s_name")%></option><%end if%><%rsa.movenextloopend ifrsa.closeset rsa=nothing%><% if  bol_add_item = 0 then %>          <option selected value="">--请选择--</option>          <% end if %></select><input type=text name="p_sort" value="<%=rs("p_sort")%>" size="20">
原创粉丝点击