Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Re: asp:listbox and multiple selection


Message #1 by "Ashley Pace" <apace@l...> on Mon, 1 Oct 2001 14:16:51
Chris--



Thanks for the note, but I've tried that and it doesn't seem to work. It 

will only tell me that one item has been selected even if more have. It's 

really driving me crazy!



> Hi Ashley,

> 

> You could loop through the Items collection of the listbox, checking the

> .Selected property for each (if selected, grab the .Value).

> 

> Chris

> 

> ----- Original Message -----

> From: "Ashley Pace" <apace@l...>

> To: "ASP+" <aspx@p...>

> Sent: Monday, September 24, 2001 4:42 PM

> Subject: [aspx] asp:listbox and multiple selection

> 

> 

> > Has anyone had a problem with looping through all the items in the 

listbox

> > and determining if each one is selected?  I've found the code to do 

this,

> > but when I select multiple items and submit the page, it's only saying

> > that one was selected.  I did set the selectionmode to multiple and 

it's

> > passing that I selected more that one item if I look at the form values

> > that are passed.  Can anyone help?

Message #2 by "Chris Scott" <chris@e...> on Mon, 1 Oct 2001 18:17:36 -0700
Hi Ashley,



The following code snippet lists out multiple selected values from a list

box.



private void Page_Load(object sender, System.EventArgs e)

{

 if(!IsPostBack)

 {

  ListBox1.Items.Add("Homer");

  ListBox1.Items.Add("Marge");

  ListBox1.Items.Add("Bart");

  ListBox1.Items.Add("Lisa");

  ListBox1.Items.Add("Maggie");

 }

 else

 {

  string myString="Selected Items: ";

  for(int a=0; a<ListBox1.Items.Count; a++)

  {

   if(ListBox1.Items[a].Selected)

   {

    myString+=ListBox1.Items[a].Value + "<br />";

   }

  }

  Label1.Text=myString;

 }

}



Best regards,



Chris





----- Original Message -----

From: "Ashley Pace" <apace@l...>

To: "ASP+" <aspx@p...>

Sent: Monday, October 01, 2001 2:16 PM

Subject: [aspx] Re: asp:listbox and multiple selection





> Chris--

>

> Thanks for the note, but I've tried that and it doesn't seem to work. It

> will only tell me that one item has been selected even if more have. It's

> really driving me crazy!

>

> > Hi Ashley,

> >

> > You could loop through the Items collection of the listbox, checking the

> > .Selected property for each (if selected, grab the .Value).

> >

> > Chris

> >

> > ----- Original Message -----

> > From: "Ashley Pace" <apace@l...>

> > To: "ASP+" <aspx@p...>

> > Sent: Monday, September 24, 2001 4:42 PM

> > Subject: [aspx] asp:listbox and multiple selection

> >

> >

> > > Has anyone had a problem with looping through all the items in the

> listbox

> > > and determining if each one is selected?  I've found the code to do

> this,

> > > but when I select multiple items and submit the page, it's only saying

> > > that one was selected.  I did set the selectionmode to multiple and

> it's

> > > passing that I selected more that one item if I look at the form

values

> > > that are passed.  Can anyone help?

>

  Return to Index