DropDownList的问题:当我选中一个下拉选项时,选中值出现在旁边的TEXT框中
DropDownList的问题:当我选中一个下拉选项时,选中值出现在旁边的TEXT框中
[解决办法]
要不要刷新页面?
[解决办法]
<%@ 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>