0

foreach (Book b in o.list) { ListBox_Items.Items.Add(b.Title); }

After I do this, the titles are now showing up in the listbox.

When I make a selection (Single Mode), ListBox_Items (Screen) is highlighting the row selected, but event SelectedIndexChanged is not triggering.

protected void ListBox_Items_SelectedIndexChanged(object sender, EventArgs e)
{
  int i = ListBox_Items.SelectedIndex;
}

ID="ListBox_Items" runat="server" EnableViewState="False" Width="400px" Rows="25" onselectedindexchanged="ListBox_Items_SelectedIndexChanged"

Any ideas ?

Michael

Edit 1 : Thanks to everyone for helping out. Got it to work now. Anyway, I had to turn on EnableViewState to True too. Because I have a "Remove" button to remove items from the listbox control, if EnableViewState is False, whenever I clicked the Remove button, the listbox becomes empty again.

3 Answers 3

5

Add AutoPostBack="True" in your aspx tag

Sign up to request clarification or add additional context in comments.

Comments

0

Try the following code.

<asp:ListBox ID="ListBox_Items" 
             runat="server" 
             EnableViewState="False" 
             Width="400px" 
             Rows="25" 
             OnSelectedIndexChanged="ListBox_Items_SelectedIndexChanged"
             AutoPostBack="true"></asp:ListBox>

1 Comment

hi ian, really appreciate your help
0

Do you have anything to make the page post back to the server?

You may need either a submit button, or you can add the property AutoPostBack="true" to your ListBox control.

See this MSDN Article for more information.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.autopostback.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.