Hi I have six ListBoxes with names from different sources. Now I would like to get the name of the selected item in the most recently selected ListBox. How do I do that? I can't simply use ListBox.S开发者_如何学编程electedItem because I don't know what ListBox I want to get my information from.
I'm assuming you are responding to the event. If so, the sender object should be the listbox that fired the event.
ListBox lb = (ListBox)sender;
var item = lb.SelectedItem;
Each ListBox will have its own SelectedIndexChanged event, from there you'll know which ListBox it was which fired the event and then be able to use your SelectedItem property
Make sure you have autopostback="true"
set on each ListBox then the page will postback as soon as a name is selected, and you can use the sender object in the event handler to find out which ListBox was used.
精彩评论