C#,从两个列表框之一获取最新选定的值
你好 我有六个列表框,其名称来自不同的来源。现在我想获取最近选择的列表框中所选项目的名称。我该怎么做?我不能简单地使用 ListBox.SelectedItem 因为我不知道我想从哪个 ListBox 获取信息。
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.SelectedItem because I don't know what ListBox I want to get my information from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您正在响应该事件。如果是这样,发送者对象应该是触发该事件的列表框。
I'm assuming you are responding to the event. If so, the sender object should be the listbox that fired the event.
每个列表框都有自己的 SelectedIndexChanged 事件,从那里您将知道触发该事件的列表框,然后能够使用您的 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
确保在每个 ListBox 上设置了
autopostback="true"
,然后一旦选择名称,页面就会回发,并且您可以在事件处理程序中使用发送者对象来找出哪个 ListBox用过的。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.