You will use this controls to dispaly set of items,
when you click on item in the list,selectedindexchanged
event will be fired.anyway by default nothing happens with
this event.
if you want an action has to be occured.you should make autopostback="True".so whenever an event should fire and
need to data to be postedback you will use this..
here is an example of autopostback..
Source Code:
Expand|Select|Wrap|Line Numbers
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:ListBox ID="lb1" Rows="4" runat="server" AutoPostBack="true" >
- <asp:ListItem>India</asp:ListItem>
- <asp:ListItem>Southafrica</asp:ListItem>
- <asp:ListItem>Australia</asp:ListItem>
- <asp:ListItem>England</asp:ListItem>
- </asp:ListBox>
- <br />
- <br />
- <asp:Label ID="lab1" runat="server">
- </asp:Label>
- </div>
- </form>
- </body>
Expand|Select|Wrap|Line Numbers
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void lb1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (lb1.SelectedItem != null)
- {
- lab1.Text = "you selected" + lb1.SelectedItem.Value;
- }
- else
- {
- lab1.Text = "";
- }
- }