Click here to Skip to main content
16,019,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
Posted
Updated 16-May-12 9:15am
v2

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

Sample:
XML
<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>

C#
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 $Item 4."
}
 
Share this answer
 
Comments
Wendelius 16-May-12 15:59pm    
Good example!
Sandeep Mewara 17-May-12 1:29am    
Thanks Mika.
sathiserg 17-May-12 5:40am    
Thanks a lot
Sandeep Mewara 23-May-12 2:51am    
Welcome.
Most likely you haven't set the AutoPostBack[^] to true
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-May-12 15:29pm    
Probably; a 5.
--SA
Wendelius 16-May-12 15:30pm    
Thanks SA :)
Sandeep Mewara 16-May-12 15:52pm    
My 5! Possible reason.
Wendelius 16-May-12 15:59pm    
Thanks Sandeep :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900