有一个DropDownList和TextBoxDropDownList内容是从数据库中读出来的。。选择DropDownList里的项,让DropDownList的DataValueField值给TextBox比如DropDownList的值有如下DataValueField DataTextField
1 aaaa
2 bbbb
3 cccc
4 dddd选择aaaa,TextBox=1
再选择cccc,TextBox=1,3这样的功能。。怎么实现??
1 aaaa
2 bbbb
3 cccc
4 dddd选择aaaa,TextBox=1
再选择cccc,TextBox=1,3这样的功能。。怎么实现??
<head runat="server">
<title>无标题页</title>
<script>
function change(objddl)
{
if(document.getElementById("TextBox1").value=="")
document.getElementById("TextBox1").value +=objddl.options[objddl.selectedIndex].innerText;
else
document.getElementById("TextBox1").value +=","+objddl.options[objddl.selectedIndex].innerText;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" onchange="change(this)">
<asp:ListItem Text="aaaa" Value="1"></asp:ListItem>
<asp:ListItem Text="bbbb" Value="2"></asp:ListItem>
<asp:ListItem Text="cccc" Value="3"></asp:ListItem>
<asp:ListItem Text="dddd" Value="4"></asp:ListItem>
</asp:DropDownList><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
{
Response.Write(TextBox1.Text);
}aaaa,bbbb,cccc,dddd
然后在DropDownList的SelectedIndexChanged事件中写处理代码:
this.TextBoxName.Text = this.DropDownListName.SelectedValue就可以了。
document.getElementById("TextBox1").value +=objddl.options[objddl.selectedIndex].value;
else
document.getElementById("TextBox1").value +=","+objddl.options[objddl.selectedIndex].value;