日期:2014-05-18 浏览次数:20582 次
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void dpFruit_SelectedIndexChanged(object sender, EventArgs e)
{
txtFruit.Text = dpFruit.SelectedItem.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="dpFruit" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dpFruit_SelectedIndexChanged">
<asp:ListItem>苹果</asp:ListItem>
<asp:ListItem>桔子</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtFruit" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
------解决方案--------------------
也可以有javascript
onchange事件
------解决方案--------------------
<asp:DropDownList ID="DropDownList1" onchange="test();" runat="server">
<asp:ListItem Text="a" Value="0"></asp:ListItem>
<asp:ListItem Text="b" Value="1"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<script language="javascript" type="text/javascript">
function test()
{
document.getElementById("TextBox1").value = document.getElementById("DropDownList1").value;
}
</script>