Click to See Complete Forum and Search --> : problem in Using ListBox


vivekshah
June 11th, 2007, 05:41 AM
Hi

I have an Web application in C#.
ON the form I have two list box say ListBox1 and ListBox2.

ListBox1 has items binded through an SQL query.
and I want to add the selected contents of ListBox1 to ListBox2 on the button click.

I tried and below is my code on button click.



for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{
ListBox2.Items.Add(ListBox1.Items[i]);
}
}
--------------------
and also tried

foreach(ListItem item inListBox1.Items)
{
if(item.Selected)
{
ListBox2.Items.Add(item);
}
}



On clicking the button selected values from ListBox1 is not moved to ListBox2..

I want to do it only through Server side code only....?

Any Idea where could be the problem

bhuraasif
June 11th, 2007, 07:22 AM
what error r u facing ?

eventhough try like

the first approach try with

ListBox1_SelectedIndexChanged

make ListBox1 autopost back to true

and try it vl work


then put ur code to button click event

ASIF

vivekshah
June 11th, 2007, 11:27 AM
thnx

I got the solution