Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

ASP.Net "truth is out there

  Asked By: Ella    Date: Jun 01    Category: Asp.net    Views: 1296
  

I have ASP.Net page with two List Box.User can add/remove items from
list1/list2.Given Below is code.It seems that I can add items from
list 1 to 2 but I could not remove items from list2. When I debug the
code to remove items with some items selected in in list2, it shows
item.selected property false for all items.Surprisingly I can add
items from list1 to list2 using same logic.Any ideas


private void Button1_Click(object sender, System.EventArgs e)
{
//Add Name WORKS

foreach(ListItem userItem in List1.Items)
{
if (userItem.Selected == true)
{
List2.Items.Add (new ListItem
(userItem.Text,userItem.Value));
}
}
foreach(ListItem userItem in List2.Items)
{
List1.Items.Remove(userItem);
}
}

private void Button2_Click(object sender, System.EventArgs e)
{
//Remove Name Does not work
EJCAHO.Components.CJTeam JT = new EJCAHO.Components.CJTeam();

foreach(ListItem userItem in List2.Items)
{
if (userItem.Selected == true)
{
List1.Items.Add (new ListItem
(userItem.Text,userItem.Value));
}
}

foreach(ListItem userItem in List1.Items)
{
List2.Items.Remove(userItem);

}
}

Share: 



Tagged: