Tuesday, March 4, 2008

Move Item Between ListBox

Program To Move Item Between ListBox (Select/Deselect All, Move Single Item, MultiSelect)

// JScript File(JSList.js)

var srclb,destlb;
var Flag ;
function moveAll(evt)

if(evt.id == 'btnSel' || evt.id == 'btnADitem')
srclb = document.getElementById('lboxSource');
destlb =document.getElementById('lboxdest');
else if(evt.id == 'btnDesel' || evt.id == 'btnRMitem')
srclb = document.getElementById('lboxdest');
destlb =document.getElementById('lboxSource');
if(srclb != null && destlb != null)
Flag = true;
Flag = false;
for(var i=0;i<srclb.length;i++)
if(evt.id == 'btnADitem' || evt.id == 'btnRMitem')
else if(evt.id == 'btnSel' || evt.id == 'btnDesel')

function exChange(iVal)
Flag = true;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBox.aspx.cs"
Inherits="ListBox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">


<script type="text/javascript" language="javascript" src="JavaScript/JSList.js"></script>

<form id="form1" runat="server">
<asp:ListBox ID="lboxSource" SelectionMode="Multiple"
runat="server" Height="122px" Width="45px">
<td style="width: 31px">

<input id="btnDesel" title="DeselectAll" type="button"
style=" position:relative; left: 3px; width: 27px; top: 88px; height: 27px;"
onclick="moveAll(this);" value="««" />

<input id="btnRMitem" title="Remove Item" type="button"
style=" position:relative; left: 3px; width: 27px; top: 35px; height: 25px;"
onclick="moveAll(this);" value="«" />

<input id="btnADitem" title="Add Item" type="button"
style=" position:relative; left: 3px; width: 26px; top: -23px; height: 29px;"
onclick="moveAll(this);" value="»" />

<input id="btnSel" title="SelectAll" type="button"
style=" position:relative; left: 3px; width: 25px; top: -83px; height: 28px;"
onclick="moveAll(this);" value="»»" />

<asp:ListBox ID="lboxDest" SelectionMode="Multiple"
runat="server" Height="122px" Width="45px"></asp:ListBox>

1 comment:

Cannon The Catalyst said...

This is an awesome post and exactly what I need on the front end. However, on the backend when I go to grab values from the destination listbox, it tells me that there are no items in it.