asp.net列表框中的事件 [英] Event in asp.net list box

查看:71
本文介绍了asp.net列表框中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在列表框事件处理程序中编写代码,我正在尝试valuechanged indexchanged 事件,但无法获取该事件.


请帮助我...

解决方案

很可能您没有设置AutoPostBack [ MSDN:ListControl.SelectedIndexChanged事件 [ ^ ]

样本:

 <  表格    id   ="     runat   ="  <   asp:ListBox     id   ="  
                   span>          ="   ListBox1_SelectedIndexChanged" 
                        ="   true" 
                        ="  服务器" <   asp:ListItem  >  Item 1 <  /asp:ListItem  > 
         <   asp:ListItem  >  Item 2 <  /asp:ListItem  > 
         <   asp:ListItem  >  Item 3 <  /asp:ListItem  > 
         <   asp:ListItem  >  Item 4 <  /asp:ListItem  > 
         <   asp:ListItem  >  Item 5 <  /asp:ListItem  > 
         <   asp:ListItem  >  Item 6 <  /asp:ListItem  > 
       <  /asp:ListBox  > 

       <   asp:Label     id   ="   runat   服务器" > 
    <  /form  >  


 受保护的 无效 ListBox1_SelectedIndexChanged(对象发​​件人,EventArgs e)
{
    Label1.Text = "  + ListBox1.SelectedItem.Text +
                     "  + ListBox1.SelectedItem.价值+
                     " ;
   // 选择Item4会得出:您选择的Item 4的值为


How can i write the code in list box event handler, i am trying valuechanged and indexchanged event but i can not get the event.


please help me...

解决方案

Most likely you haven''t set the AutoPostBack[^] to true


Here, have a look at how it can be done:
MSDN: ListControl.SelectedIndexChanged Event[^]

Sample:

<form id="form1" runat="server">
       <asp:ListBox id="ListBox1"

            OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"

            AutoPostBack="true"

            runat="server">
         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>
       </asp:ListBox>

       <asp:Label id="Label1" runat="server"/>
    </form>


protected void  ListBox1_SelectedIndexChanged(object sender, EventArgs e) 
{
    Label1.Text = "You selected " + ListBox1.SelectedItem.Text +
                     " with a value of


" + ListBox1.SelectedItem.Value + "."; // Selection of Item4 gives: "You selected Item 4 with a value of


这篇关于asp.net列表框中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆