首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ASP.NET 的ListBox有关问题

2012-01-16 
ASP.NET 的ListBox问题我打算单击ListBox中一项后会在同一页面上的另一个文本框里显示这一项的text,能使用

ASP.NET 的ListBox问题
我打算单击ListBox中一项后会在同一页面上的另一个文本框里显示这一项的text,     能使用ListBox的SelectedIndexChanged   事件吗?   要让这个事件起作用要把autoPostBack设为true,   可页面一刷新后,ListBox中选中的项没了```  


 


[解决办法]
aspx:
<asp:ListBox ID= "ListBox1 " runat= "server " AutoPostBack= "True " OnSelectedIndexChanged= "ListBox1_SelectedIndexChanged "> </asp:ListBox>
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox>

cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox1.Items.Add(new ListItem( "1 ", "1 "));
ListBox1.Items.Add(new ListItem( "2 ", "2 "));
ListBox1.Items.Add(new ListItem( "3 ", "3 "));
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.TextBox1.Text = ListBox1.SelectedItem.Text;
}

热点排行