using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MovingListItemsInListbox
{
public partial class MovingLIstIten : System.Web.UI.Page
{
ArrayList arrList1 = new ArrayList();
ArrayList arrList2 = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn1_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
if (ListBox1.Items.Count > 0)
{
if (ListBox1.SelectedIndex >= 0)
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
if (!arrList1.Contains(ListBox1.Items[i]))
{
arrList1.Add(ListBox1.Items[i]);
}
}
}
for (int i = 0; i < arrList1.Count; i++)
{
if (!ListBox2.Items.Contains((ListItem)arrList1[i]))
{
ListBox2.Items.Add((ListItem)arrList1[i]);
}
ListBox1.Items.Remove((ListItem)arrList1[i]);
}
ListBox2.SelectedIndex = -1;
arrList1.Clear();
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "Please select atlest one list item for move";
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "There is no items in listbox1";
}
}
protected void btn2_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
if (ListBox1.Items.Count > 0)
{
while (ListBox1.Items.Count != 0)
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
ListBox2.Items.Add(ListBox1.Items[i]);
ListBox1.Items.Remove(ListBox1.Items[i]);
}
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "There is no items in list box1 for move";
}
}
protected void btn3_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
if (ListBox2.Items.Count > 0)
{
if (ListBox2.SelectedIndex >= 0)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox2.Items[i].Selected)
{
if (!arrList2.Contains(ListBox2.Items[i]))
{
arrList2.Add(ListBox2.Items[i]);
}
}
}
for (int i = 0; i < arrList2.Count; i++)
{
if (!ListBox1.Items.Contains((ListItem)arrList2[i]))
{
ListBox1.Items.Add((ListItem)arrList2[i]);
}
ListBox2.Items.Remove((ListItem)arrList2[i]);
}
ListBox1.SelectedIndex = -1;
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "Please select atleast one listItem for move";
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "There is no listitem in List box2";
}
}
protected void btn4_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
if (ListBox2.Items.Count > 0)
{
while (ListBox2.Items.Count > 0)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
ListBox1.Items.Add(ListBox2.Items[i]);
ListBox2.Items.Remove(ListBox2.Items[i]);
}
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "There is no items in list box2 for move";
}
}
}
}