
connectiongstring
=
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString
SqlConnection
sqlcon
=
new
SqlConnection(connectiongstring)
string
Brand
=
BDropDownList.SelectedValue.ToString()//下拉列表
string
CmdText
=
"SELECT
Model
FROM
[CarType]
WHERE
Brand=\'"
+
Brand
+
"\'"
SqlCommand
sqlcom
=
new
SqlCommand(CmdText,
sqlcon)
try
{
sqlcon.Open()
SqlDataReader
dr
=
sqlcom.ExecuteReader()
。。。。。。。。。。
}
catch
(SqlException
ex)
{
}
//清理
finally
{
if
(sqlcon
!=
null)
{
sqlcon.Close()
}
}
还有需要注意的是autopostback属性设置成true
思路是这样的:首先连接数据库,然后讲下来列表框赋值,然后在下拉列表框的onchenge事件写上代码:text1.value=this.option[selectedindex].value就可以实现了!
先把下面的静态页面的代码你去测试一下就知道了
=================================================
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form action="" method="get" name="form1">
<label>
<input name="text1" type="text" id="text1" value="aa" size="10">
</label>
<label>
<select name="select" onchange="document.form1.text1.value=this.options[this.selectedIndex].value">
<option value="1">cc</option>
<option value="2">dd</opticon>
<option value="3">33</option>
</select>
</label>
</form>
</body>
</html>
================================================
<!--#include file "conn.asp"-->
<%
set rst=server.CreateObject("adodb.recordset")
sqlt="select * from hd order by id desc"
rst.open sqlt,conn,1,1
%>
<form name="form1" method="post" action="">
<label>
<input name="text1" type="text" id="text1" size="10">
</label>
<select name="select" onchange="document.form1.text1.value=this.options[this.selectedIndex].value">
<%while not rst.eof%>
<option value="<%=rst("id")%>"><%=rst("hdmc")%></option>
<% rst.movenext
wend%>
</select>
</form>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)