Hi
I want 2 ListBoxes/DropDown with Checkboxes. In one ListBox/DropDowm i will be listing all Departments . Between 2 Boxes there will be 2 arrows (Left & Right) . When user ticks checkboxes then all those selected Department from Left Box & select right arrow that Department's should get moved in the Right box & vice-versa using C# . Then i want all those Departments which are in Right Side Box i want then to assign Deptt Head . Then i want them to be saved . How best it can be done.
Thanks
I want 2 ListBoxes/DropDown with Checkboxes. In one ListBox/DropDowm i will be listing all Departments . Between 2 Boxes there will be 2 arrows (Left & Right) . When user ticks checkboxes then all those selected Department from Left Box & select right arrow that Department's should get moved in the Right box & vice-versa using C# . Then i want all those Departments which are in Right Side Box i want then to assign Deptt Head . Then i want them to be saved . How best it can be done.
Thanks
Satyapriya NayakPosted Nov 27, 2011, 1:46 PM
Better use CheckBoxList instead of listbox.If so then the solution is as below.
<%@ 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)
{
CheckBoxList1.Items.Add("Raj");
CheckBoxList1.Items.Add("Ravi");
CheckBoxList1.Items.Add("Rahul");
CheckBoxList1.Items.Add("Raju");
CheckBoxList1.Items.Add("Rohit");
CheckBoxList1.Items.Add("Rajesh");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = CheckBoxList1.Items.Count - 1; i >= 0; i--)
{
if (CheckBoxList1.Items[i].Selected)
{
CheckBoxList2.Items.Add(CheckBoxList1.Items[i]);
CheckBoxList2.ClearSelection();
CheckBoxList1.Items.Remove(CheckBoxList1.Items[i]);
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = CheckBoxList2.Items.Count - 1; i >= 0; i--)
{
if (CheckBoxList2.Items[i].Selected)
{
CheckBoxList1.Items.Add(CheckBoxList2.Items[i]);
CheckBoxList1.ClearSelection();
CheckBoxList2.Items.Remove(CheckBoxList2.Items[i]);
}
}
}
}
Thanks
If this post helps you mark it as answer
Jagjit SainiPosted Nov 28, 2011, 12:25 AM
There is 1 issue it does not show second CheckList Box since it is Blank when page loads. Similarly if we select all Checkboxes and move to second Box then first does not display . What i want that even if it is blank it should display . Secondly is it possible whenever we select any Department it should not PostBack.
Thanks
Sam HobbsPosted Nov 27, 2011, 1:43 PM
Then you need to determine how to do each one of those as separate tasks; you can ask for help with each one sepparately if you need help.