C#如何将下拉列表中选中的数据放入文本框

前台代码:<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1">哈哈</asp:ListItem>
<asp:ListItem Value="2">吼吼</asp:ListItem>
</asp:DropDownList>
</form>
后台代码:protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (DropDownList1.Items[0].Selected == true)
{
TextBox1.Text = DropDownList1.Items[1].Value;
}
else
{
TextBox1.Text = DropDownList1.Items[0].Value;

}
}
}
当列表框里的内容从新选时,前面的文本框里的内容不变化

第1个回答  2010-08-09
可以在SelectedIndexChanged事件中设置 比如
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedValue ;
}本回答被提问者和网友采纳
第2个回答  2010-08-09
在下拉列表框的SelectIndexChange事件中对当前选中的值进行设置。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网