级联下拉列表

本文介绍了一种使用 ASP.NET 和 ADO.NET 进行数据库操作的方法,并展示了如何利用 JavaScript 实现页面上的动态下拉框选择功能。通过示例代码,读者可以了解到如何连接数据库、获取数据并填充到网页的下拉框中,同时实现根据用户的选项动态更新子级下拉框内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

<%
dim count
set rs7=server.createobject("adodb.recordset")
rs7.Source= "select * from SmallClass order by zs_id desc"
rs7.open rs7.Source,conn,1,1
%>
 
 
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
        <%
        count = 0             
        do while not rs7.eof
        %>
subcat[<%=count%>] = new Array("<%=rs7("SmallClassName")%>","<%=rs7("bigclassname")%>","<%=rs7("SmallClassname")%>");
        <%
        count = count + 1
        rs7.movenext
        loop
        rs7.close
              set rs7=nothing
        %>
onecount=<%=count%>;
 
function changelocation(locationid)
    {
    document.form1.smallclassname.length = 0;
 
    var locationid=locationid;
    var i;
 
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            {
 
                document.form1.smallclassname.options[document.form1.smallclassname.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
       
    }   
</script>
 
 
请选择栏目:
        <select name="bigclassname" onChange="changelocation(document.form1.bigclassname.options[document.form1.bigclassname.selectedIndex].value)" size="1">
          <option selected value="<%=bigclassname%>"><%=bigclassname%></option>
          <%        
set rs8=server.CreateObject("ADODB.RecordSet")
rs8.Source="select * from BigClass order by zs_id"
rs8.Open rs8.Source,conn,1,1
        do while not rs8.eof
        %>
          <option value="<%=rs8("bigclassname")%>"><%=rs8("bigclassname")%></option>
          <%
        rs8.movenext
        loop
        rs8.close
              set rs8=nothing
        %>
        </select>
        小类
        <select name="smallclassname">
          <option selected value="<%=smallclassname%>"><%=smallclassname%></option>
          <%        
set rs8=server.CreateObject("ADODB.RecordSet")
rs8.Source="select * from smallclass where bigclassname='"&bigclassname&"' order by zs_id"
rs8.Open rs8.Source,conn,1,1
        do while not rs8.eof
        %>
          <option value="<%=rs8("smallclassname")%>"><%=rs8("smallclassname")%></option>
          <%
        rs8.movenext
        loop
        rs8.close
              set rs8=nothing
        %>
        </select>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值