开发者

C#, Get latest selected value from one of two ListBoxes

开发者 https://www.devze.com 2023-03-04 08:30 出处:网络
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开

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号