如何在列表框控件中获取listitem [英] how can I get the listitem in the listbox control
本文介绍了如何在列表框控件中获取listitem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Webform中有一个列表框控件,我希望通过触发listbox的SelectedIndexChanged事件来获取listitem,并在文本框控件中显示该项。但是当我在列表框中改变选择项时,我无法获得列表项,文本框中没有显示任何内容,任何人都可以帮助我吗?谢谢
There is a listbox control in my Webform, I want to get the listitem by trigger the SelectedIndexChanged event of listbox, and display the item in a textbox control. but when I chang the selecteditem in the listbox, I cann't get the listitem and nothing displayed in the textbox, anyone can help me? thanks
推荐答案
您可以从
You can get selected items from
var selectedQuery = listBox.Items.Cast<listitem>().Where(item => item.Selected);
然后使用String.Join()把它放在你的文本框中。希望你能理解你需要做什么。
编辑:
或者你可以尝试..
And then put this in your textbox using String.Join().Hope you can understand what you need to do.
EDIT:
Alternately you can try..
string values = String.Join(" ", listbox.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToArray());
这篇关于如何在列表框控件中获取listitem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文