access 下拉列表联动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了access 下拉列表联动相关的知识,希望对你有一定的参考价值。

我在ACCESS做了一个表,表里其中两个字段做成了下拉菜单,我想让这两个下拉菜单里的数据根据我选择的不同而联动,如何实现???
代码在哪里输入?我是初学者,而且我没有做控件,我只是调整了 数据类型的查阅属性

不太明白什么叫"代码在哪里输入"???
当然是用DW打开,将旧的不联动的下拉菜单换成下面的代码,这里的代码还要根据你的实际情况修改一下.

我给两个代码,一个是联动式二级下拉菜单,另一个是多级联动菜单:

1.联动式二级下拉菜单
<%
set rs=server.createobject("adodb.recordset")
sql = "select * from ProSmallClass where IsShow=True order by Descs Asc"
rs.open sql,conn,1,1
%>
<script language = "javascript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("Title"))%>","<%= trim(rs("B_ID"))%>","<%= trim(rs("S_ID"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
set rs=nothing
%>
onecount=<%=count%>;

function changelocation(locationid)

document.form1.ProSmallClass.length = 0;

var locationid=locationid;
var i;
document.form1.ProSmallClass.options[0] = new Option('=所属小类=','');
for (i=0;i < onecount; i++)

if (subcat[i][1] == locationid)

document.form1.ProSmallClass.options[document.form1.ProSmallClass.length] = new Option(subcat[i][0], subcat[i][2]);




</script>

<form name="form1" method="POST" action="?work=P_add" >
<select name="ProBigClass" size="1" id="ProBigClass" onChange="changelocation(document.form1.ProBigClass.options[document.form1.ProBigClass.selectedIndex].value)">
<%
set rs=server.createobject("adodb.recordset")
sql = "select * from ProBigClass where IsShow=True order by Descs Asc"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
%>
<option value="" selected>=所属大类=</option>
<%else%>
<option value="" selected>=所属大类=</option>
<%
do while not rs.eof
%>
<option value="<%=trim(rs("B_ID"))%>"><%=trim(rs("Title"))%></option>
<%
rs.movenext
loop
end if
rs.close
set rs = nothing
%>
</select>
<select name="ProSmallClass" id="ProSmallClass">
<option selected value="">=所属小类=</option>
</select> </form>

2.三级联动菜单 四级联动菜单 多级联动菜单
<%
dim cid,coid
cid = request("cid") 'cid 大类id
coid = request("coid") 'coid 中类id
set rs=server.createobject("adodb.recordset")
sql = "select * from edu_c" '表一 大类表
rs.open sql,conn,1,1
strOption1 = "<option value='' selected >==请选择所属市局==</option>"
do while not rs.eof
if cstr(rs("id")) = cstr(cid) then
strOption1 = strOption1 & "<option value='" & rs("id") & "' selected>" & rs("c_name") & "</option>"
else

strOption1 = strOption1 & "<option value='" & rs("id") & "'>" & rs("c_name") & "</option>"

end if
rs.movenext
loop

rs.close

if cid <> "" then
sql = "select * from edu_co where c_id=" & cid '表二 中类表 bid==表一中的id

rs.open sql,conn,1,1
strOption2 = "<option value='' selected >==请选择所属县局==</option>"

do while not rs.eof
if cstr(rs("id")) = cstr(coid) then
strOption2 = strOption2 & "<option value='" & rs("id") & "' selected>" & rs("co_name") & "</option>"
else
strOption2 = strOption2 & "<option value='" & rs("id") & "'>" & rs("co_name") & "</option>"
end if
rs.movenext
loop
rs.close
end if

if coid <> "" then
sql = "select * from edu_s where co_id= " & coid '表三 小类表 mid==表二的id
rs.open sql,conn,1,1
strOption3 = "<option value='' selected >==请选择学校==</option>"
while not rs.eof
if cstr(rs("id")) = cstr(sid) then
strOption3 = strOption3 & "<option value='" & rs("id") & "' selected>" & rs("s_name") & "</option>"
else
strOption3 = strOption3 & "<option value='" & rs("id") & "'>" & rs("s_name") & "</option>"
end if

rs.movenext
wend
rs.close
end if

%>
<select onchange="changeb(this.value)" name="cid"><%=strOption1%></select>
<select onchange="change(this.value)" name="coid"><%=strOption2%></select>
<select name="sid"><%=strOption3%></select>
<script language="javascript">
<!--
function changeb(cid)
location.assign("three.asp?action=s_s&cid=" + cid);


function change(coid)
location.assign("three.asp?action=s_s&cid=<%=cid%>&coid=" + coid);

-->
</script>
参考技术A 给你我自己用的,你修改看看

<script language="JavaScript" type="text/javascript">
<!--
var subcat = new Array();
<%
set car_s = conn.execute ("select * from pro_car where cate_by=2 order by cate_sid desc")
if car_s.eof and car_s.bof then
else
k=0
do while not car_s.eof %>
subcat[<%=k%>] = new Array('<%=car_s("cate_sid")%>','<%=car_s("cate_name")%>','<%=car_s("cate_id")%>')
<% k=k+1
car_s.movenext
loop
end if
car_s.close
set car_s=nothing %>
function changeselect1(locationid)
document.checkform.u_car2.length = 0;
document.checkform.u_car2.options[0] = new Option('==请选择车型==','');
for (i=0; i<subcat.length; i++)
if (subcat[i][0] == locationid)
document.checkform.u_car2.options[document.checkform.u_car2.length] = new Option(subcat[i][1], subcat[i][2]);


//-->
</script>
<select name="u_car1" onChange="changeselect1(this.value)">
<option value="" selected="selected">==请选择厂商==</option>
<%
set car = conn.execute ("select * from pro_car where cate_by=1 order by cate_order desc")
if car.eof and car.bof then
else
do while not car.eof %>
<option value="<%=car("cate_id")%>"><%=car("cate_name")%></option>
<% car.movenext
loop
end if
car.close
set car=nothing %>
</select>

<select name="u_car2" id="u_car2">
<option value="">==请选择车型==</option>
</select>

以上是关于access 下拉列表联动的主要内容,如果未能解决你的问题,请参考以下文章

关于ligerUI下拉列表两级联动的问题

二级联动asp下拉式列表菜单

Axure7 两个下拉列表联动,第一个下拉列表选中某项后,删除第二个下拉列表中的项

asp 2级联动菜单,动态获取2级下拉列表,2级列表来自两个表,求该,问起解决再加100分

文本框实现下拉列表联动

jquery select2 联动下拉列表赋值二级下拉列表赋不上值,怎么搞