文件一
Product.asp
<%
'商品类
Class Product
Private mID
Private mName
Private mOrigin
Private mPrice
Public Property Let Price(vData)
mPrice=vData
End Property
Public Property Get Price()
ID=mPrice
End Property
Public Property Let Origin(vData)
mOrigin=vData
End Property
Public Property Get Origin()
ID=mOrigin
End Property
Public Property Let ID(vData)
mID=vData
End Property
Public Property Get ID()
ID=mID
End Property
Public Property Let Name(vData)
mName=vData
End Property
Public Property Get Name()
ID=mName
End Property
'读取商品方法
Public Function ReadProduct(con)
Dim rsPro
Set rsPro=con.Execute("select * from 商品编码='"&mID&"'")
ReadRecordSet rsPro
rsPro.Close
Set rsPro=Nothing
End Function
'返回商品编号列表
Public Function GetProductIDList(con)
Dim rsPro
Set rsPro=con.Execute("select 商品编码 from shpm")
Do Until rsPro.EOF
GetProductIDList=GetProductIDList&"<option value="&rsPro(0)&" >"&rsPro(0)&"</option>"
rsPro.MoveNext
Loop
rsPro.Close
Set rsPro=Nothing
End Function
Private Sub ReadRecordSet(rsPro)
mID=rsPro(0)
mName=rsPro(1)
mOrigin=rsPro(2)
mPrice=rsPro(3)
End Function
Private Sub FillRecordSet(rsPro)
rsPro(0)=mID
rsPro(1)=mName
rsPro(2)=mOrigin
rsPro(3)=mPrice
End Function
End Product
%>
文件二:主文件
<html>
<head>
<#--include file="Product.asp"-->
<!--引用产品类文件-->
<!--引用你的数据库连接文件-->
<%
Dim con,ObjPro
Set con=[你的项目数据库连接对象]
Set ObjPro=New Product
IF Request("ProID")<>"" Then
ObjPro.ReadProduct con
End IF
%>
<title>下拉列表查询数据</title>
<script language="javascript">
function selPro_Change(ProID)
{
var SelfSrc=window.location.href;
self.location=SelfSrc+"?ProID="+ProID;
}
</script>
</head>
<body>
<select name="selPro" onChange="selPro_Change(this.options[this.selectedIndex].value);" >
<%
Response.Write ObjPro.GetProductIDList(con)
%>
</select>
商品编号:<%=ObjPro.ID%>
商品名称:<%=ObjPro.Name%>
产地:<%=ObjPro.Origin%>
单价:<%=ObjPro.Price%>
</body>
</html>