Click here to Skip to main content
15,887,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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
Posted
Comments
walterhevedeich 1-Aug-13 23:31pm    
You may want to post the code on the SelectedIndexChanged event and the answerers can start from there.

1 solution

You can get selected items from
C#
var selectedQuery = listBox.Items.Cast<listitem>().Where(item => item.Selected);

And then put this in your textbox using String.Join().Hope you can understand what you need to do.
EDIT:
Alternately you can try..
C#
string values = String.Join(" ", listbox.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToArray());
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900