Hi
I have 2 ListBoxes/DropDown . In one ListBox/DropDowm i will be listing all Departments . Between 2 Boxes there will be 2 arrows (Left & Right) . When user selects any Department from Left Box & select right arrow that Department should get moved in the Right box & vice-versa using C# .
Thanks
Loading
Satyapriya NayakPosted Nov 25, 2011, 12:59 PM
Here is your solution.
For DropDownList below code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("Raj");
DropDownList1.Items.Add("Ravi");
DropDownList1.Items.Add("Rahul");
DropDownList1.Items.Add("Raju");
DropDownList1.Items.Add("Rohit");
DropDownList1.Items.Add("Rajesh");
}
}
protected void btn_left_Click(object sender, EventArgs e)
{
DropDownList1.Items.Add(DropDownList2.SelectedItem.Text);
int i = 0;
i = DropDownList2.SelectedIndex;
DropDownList2.Items.RemoveAt(i);
}
protected void btn_right_Click(object sender, EventArgs e)
{
DropDownList2.Items.Add(DropDownList1.SelectedItem.Text);
int i = 0;
i = DropDownList1.SelectedIndex;
DropDownList1.Items.RemoveAt(i);
}
protected void btn_leftall_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= DropDownList2.Items.Count - 1; j++)
{
DropDownList1.Items.Add(DropDownList2.Items[j]);
}
DropDownList2.Items.Clear();
}
protected void btn_rightall_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= DropDownList1.Items.Count - 1; j++)
{
DropDownList2.Items.Add(DropDownList1.Items[j]);
}
DropDownList1.Items.Clear();
}
}
For Listbox below code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox1.Items.Add("Raj");
ListBox1.Items.Add("Ravi");
ListBox1.Items.Add("Rahul");
ListBox1.Items.Add("Raju");
ListBox1.Items.Add("Rohit");
ListBox1.Items.Add("Rajesh");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(ListBox2.SelectedItem.Text);
int i = 0;
i = ListBox2.SelectedIndex;
ListBox2.Items.RemoveAt(i);
}
protected void Button2_Click(object sender, EventArgs e)
{
ListBox2.Items.Add(ListBox1.SelectedItem.Text);
int i = 0;
i = ListBox1.SelectedIndex;
ListBox1.Items.RemoveAt(i);
}
protected void Button3_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= ListBox2.Items.Count - 1; j++)
{
ListBox1.Items.Add(ListBox2.Items[j]);
}
ListBox2.Items.Clear();
}
protected void Button4_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= ListBox1.Items.Count - 1; j++)
{
ListBox2.Items.Add(ListBox1.Items[j]);
}
ListBox1.Items.Clear();
}
}
Thanks
If this post helps you mark it as answer
VulpesPosted Nov 25, 2011, 1:49 PM
VulpesPosted Nov 25, 2011, 12:03 PM