VS里面Listbox怎么实现选中一项,在textbox里显示相应的内容?也就是Listbox怎么把值传递出来?

如题所述

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>测试</asp:ListItem>
<asp:ListItem>测试2</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

后台代码:
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListBox1.SelectedValue!=null)
{
TextBox1.Text = ListBox1.SelectedValue;
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜