看到这么多人对联动select有兴趣,特写了个无限级别联动的select SAMPLE

yonghengdizhen 2002-09-16 05:18:16
index.asp

<!--#include file="../conn/conn.asp"-->
<%
'以下为初始显示数据.可根据需求写成存储过程.
set Rs=server.createobject("adodb.recordset")
sql="(SELECT 0,product_class_id,product_class_name FROM product_class WHERE Parent_id=0)"
sql=sql & "UNION(SELECT 1,product_class_id,product_class_name FROM product_class"
sql=sql & " WHERE Parent_ID=(SELECT TOP 1 product_class_id FROM product_class WHERE Parent_id=0))"
sql=sql & "UNION(SELECT 2,product_class_id,product_class_name FROM product_class"
sql=sql & " WHERE Parent_ID=(SELECT TOP 1 product_class_id FROM product_class WHERE Parent_ID="
sql=sql & "(SELECT TOP 1 product_class_id FROM product_class WHERE Parent_id=0)))"
Rs.open sql,conn,1,1
if not Rs.EOF then
ClassInfos=Rs.GetRows()
end if
Rs.Close
%>
<html>
<head>
<title>产品列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script LANGUAGE="javascript">
function P_search()
{
if(document.searchform.Ssearch.value=="")
{
alert("没有输入关健字");
return false;
}
}

function lb_onchange(ctlname)
{
if(event.propertyName=="value")
{
classid=event.srcElement.options[event.srcElement.selectedIndex].value;
requestForm=document.createElement("FORM");
requestForm.action="class.asp?ClassID=" + classid + "&CtlName=" + ctlname
requestForm.method="post";
requestForm.target="_hideFrame";
requestForm.submit()
}
}
function show_product(ctlname)
{
if(event.propertyName=="value")
{
classid=event.srcElement.options[event.srcElement.selectedIndex].value;
requestForm=document.createElement("FORM");
requestForm.action="product.asp?ClassID=" + classid + "&CtlName=" + ctlname
requestForm.method="post";
requestForm.target="_hideFrame2";
requestForm.submit()
}
}
</script>

</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<form method="post" LANGUAGE="javascript" action="index.asp" onsubmit="return p_sesrch()" name=searchform>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="98">
<tr>
<td width="17%" height="12">按产品名查找</td>
<td width="28%" height="12">
<input type="text" name="Ssearch" style="width:100px,height:18px">
</td>
<td height="12" width="22%">
<input type="submit" name="find" value="查 找" style="width:40px,height:18px">
</td>
<td width="19%" height="12"> </td>
<td width="14%" height="12"> </td>
</tr>
<tr>
<td width="17%">产品类别:</td>
<td width="28%">
<select id="rootClass" size="1" class="box" onpropertychange="lb_onchange('childClass')">
<%
if IsArray(ClassInfos) then
for i=LBound(ClassInfos,2) to UBound(ClassInfos,2)
if ClassInfos(0,i)<>0 then exit for
%>
<option value="<%=ClassInfos(1,i)%>"><%=ClassInfos(2,i)%></option>
<%
next
end if
%>
</select>
</td>
<td width="22%" ondblclick="xxx()">
<select id="childClass" size="1" onpropertychange="lb_onchange('_class')">
<%
if IsArray(ClassInfos) then
for i=i to UBound(ClassInfos,2)
if ClassInfos(0,i)<>1 then exit for
%>
<option value="<%=ClassInfos(1,i)%>"><%=ClassInfos(2,i)%></option>
<%
next
end if
%>
</select>
</td>
<td width="19%">
<select id="_class" size="1" onpropertychange="show_product('product')">
<%
if IsArray(ClassInfos) then
for i=i to UBound(ClassInfos,2)
%>
<option value="<%=ClassInfos(1,i)%>"><%=ClassInfos(2,i)%></option>
<%
next
end if
%>
</select>
</td>
<td width="14%"> </td>
</tr>
</table>
<table id=product ondblclick="product.cells[0].innerHTML='<B>你是谁?</B>'">
<tr>
<td width="17%">共查询到:</td>
<td width="28%">条记录 目前页为</td>
<td colspan="2">链接码:</td>
<td width="14%"> </td>
</tr>
<tr align="center">
<td width="17%">删 除</td>
<td width="28%">产 品</td>
<td width="22%">型 号</td>
<td width="19%">修 改</td>
<td width="14%">添 加</td>
</tr>

<tr>
<td width="17%" align="center">
<input type="checkbox" name="delchik" value="checkbox">
</td>
<td width="28%"> </td>
<td width="22%"> </td>
<td width="19%" align="center"><img src="../image/a_edit.gif" width="52" height="16"></td>
<td width="14%" align="center"><img src="../image/a_add.gif" width="52" height="16"></td>
</tr>
</table>
</form>
<iframe name="_hideFrame" src="about:blank" height=300 width=500 style="display:none"></iframe>
<iframe name="_hideFrame2" src="about:blank" height=300 width=500 style="display:"></iframe>
</body>
</html>

class.asp
<!--#include file="../conn/conn.asp"-->
<%
if Request("ClassID")<>"" and Request("CtlName")<>"" then
%>
<SCRIPT language=javascript>
parent.document.all.<%=Request("CtlName")%>.innerHTML="";
</SCRIPT>
<%
end if
set Rs=server.createobject("adodb.recordset")
sql="SELECT product_class_id,product_class_name FROM product_class WHERE parent_id=" & Request("ClassID")
rs.Open sql,conn,1,1
if not Rs.EOF then
ClassInfos=Rs.GetRows()
end if
Rs.close
set Rs=nothing
Conn.Close
set Conn=nothing
if IsArray(ClassInfos) then
for i=LBound(ClassInfos,2) to UBound(ClassInfos,2)
%>
<SCRIPT language=javascript>
oOption=parent.document.createElement("option")
oOption.value="<%=ClassInfos(0,i)%>"
oOption.innerHTML="<%=ClassInfos(1,i)%>"
parent.document.all.<%=Request("CtlName")%>.appendChild(oOption);
</SCRIPT>
<%
next
%>
<SCRIPT language=javascript>
parent.document.all.<%=Request("CtlName")%>.options[1].selected=true;
</SCRIPT>
<%
end if
%>
...全文
82 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go_Rush 2002-11-12
  • 打赏
  • 举报
回复
...
epowerlab 2002-11-12
  • 打赏
  • 举报
回复
to : cleo(无为而为)
我想看看,你的地址不能访问
zhuyuantan 2002-11-10
  • 打赏
  • 举报
回复
有价值
epowerlab 2002-11-10
  • 打赏
  • 举报
回复
做个记号
cleo 2002-09-17
  • 打赏
  • 举报
回复
我写了一个函数,只要调用函数就ok了

我就不贴大段代码了,有兴趣就去看看吧,
http://www.500cn.com/bbs1/dispbbs.asp?boardID=4&RootID=87&ID=87
这是一个介绍:

unction M18_UDF_MultiLevelSelect_New(Name,FldCode,FldName,TableName,CodeRule,returntype)
'------------------------------------------------------
'2002-07/04 last modify
' copy from /cmsnetcn/govadmin
'注意:在form 里面不要包含有name的字段

'注意:使用时候请将这部分代码放在一个 <form name=form1 ></form>里面(form 的名字任意)
'注意:这里的编码是等长的编码。如果不是等长,请使用view转变成等长。
'注意: 我们这里假设填充字符不是$

'功能:根据记录,生成一个多级Select
'编写:刘建雄
'日期:2001-12-27
'参数: (所有参数均为字符)
' Name:需要的表单字段名称(request(Name))
' FldCode:Code的字段名
' FldName:Name的字段名
' TableName:所在Table or view name
' CodeRule:编码的规则 (编码总长度$填充字符$第一级长度$第二级长度$第三级长度$...)
' 比如:(codeRule="6$0$2$4" 这个时候第三级(最后两位)不会生成到我们的分级下拉框来)
' 编码特性:
' AA
' AB
' AAAA
' AAAB
' AAAAAB
' 应用范围:行政区域表、其他分类等。
' returntype:返回的FldCode的类型: 0 ->表示去掉了填充字符的; 1 -> 没有去掉填充字符
'使用提示:如果所要求字段不在一个table,或者字段编码不符合特性,请使用View,
'使用方法:CALL M18_UDF_MultiLevelSelect_New("ADDCODE_DZ","ADDCODE_DZ","NAME","ADDCODE","6$0$2$4",0)
yonghengdizhen 2002-09-17
  • 打赏
  • 举报
回复
to liuningjian(笨小孩)
说来看看..

是不是RDS???或者别的acitve x?
liuningjian 2002-09-17
  • 打赏
  • 举报
回复
好像用DataShaping 更简单
verygood2008 2002-09-17
  • 打赏
  • 举报
回复
wo jie
clipper_clipper 2002-09-16
  • 打赏
  • 举报
回复
珍藏
yz_ivan 2002-09-16
  • 打赏
  • 举报
回复
收藏
yonghengdizhen 2002-09-16
  • 打赏
  • 举报
回复
不是上面已经留了出口了吗???
function show_product(ctlname)
{
if(event.propertyName=="value")
{
classid=event.srcElement.options[event.srcElement.selectedIndex].value;
requestForm=document.createElement("FORM");
requestForm.action="product.asp?ClassID=" + classid + "&CtlName=" + ctlname
requestForm.method="post";
requestForm.target="_hideFrame2";
requestForm.submit()
}
}


product.asp就是从另一个表中拿数据..
处理原则同上..
实际上这个product.asp我也写出来了,只是我觉得没什么代表性.就只贴出来了一部分.其余部分,大家举一反三,很容易就能写出来.


qimangxing 2002-09-16
  • 打赏
  • 举报
回复
那要是两个数据表之间的联动呢?
lishizhen2002 2002-09-16
  • 打赏
  • 举报
回复
关注。
yonghengdizhen 2002-09-16
  • 打赏
  • 举报
回复
表结构:
product_class_id,product_class_name,parent_id
cshadow 2002-09-16
  • 打赏
  • 举报
回复
认真看看

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧