Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

listbox multivalue selection

I have a listbox which allows for multi selection.

However, I can not work out how to capture the multiple selection.

here is my code so far.

  foreach (int selectedIndex in Specialty_ListBox.SelectedItem.ToString())
    {
      Response.Write(Specialty_ListBox.SelectedItem.ToString());
       
       
    }
0
Mr_Shaw
Asked:
Mr_Shaw
  • 5
  • 3
  • 2
  • +2
2 Solutions
 
ripahoratiuCommented:
MSDN ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.web/html/060c44dc-4e57-6c29-6c13-a5123583ca82.htm:

"Use the Items collection to examine the ListItem objects contained in the ListBox control. For example, you can determine the selected item(s) in the ListBox control by enumerating the Items collection and testing the Selected value for each ListItem element."

0
 
Mr_ShawAuthor Commented:
do you have the http address for the link
0
 
tillgeffkenCommented:
Not sure which .Net Framework version you're building this on but maybe http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.getselectedindices.aspx is what you're looking for.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CuteBugCommented:
http://www.csharpfriends.com/articles/getArticle.aspx?articleID=345&page=3

foreach(ListItem i in myListBox.Items)
 { 
  if(i.Selected)
  { 
    ...  
  } 
 } 

Open in new window

0
 
Anurag ThakurTechnical ManagerCommented:
something like this should work
for (int i=0; i < this.listBox1.SelectedItems.Count; i++)
{
     //listBox1.SelectedItems[i].ToString ();
}
0
 
Mr_ShawAuthor Commented:
does anyboby have an easy example of how to do this. I am not the best at c#.
0
 
Anurag ThakurTechnical ManagerCommented:
what is there in my sample code which you dont understand
i am just looping for the selecteditems in the listbox
0
 
Mr_ShawAuthor Commented:
My IDE does not like to expression Count.
0
 
tillgeffkenCommented:

int[] selectedIndices = Specialty_ListBox.GetSelectedIndices();
foreach (int i in selectedIndices)
{
    string itemText = Specialty_ListBox.Items[i].Text;
    string itemValue = Specialty_ListBox.Items[i].Value;
    Response.Write(string.Format("Text: {0}; Value: {1}", itemText, itemValue)
}

Open in new window

0
 
Anurag ThakurTechnical ManagerCommented:
share your code and let us know u r framework
0
 
Mr_ShawAuthor Commented:
i am using .net 2
0
 
Mr_ShawAuthor Commented:
thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now