Create new Website and in Default.aspx add two Listbox (ListBox1 , ListBox2) and add items in Listbox1 and add two buttons (<< ,>>) with Id's
(btnMoveLeft,btnMoveRight)
The Javascript code will be:
//function fnMoveItems(lstbxFrom,lstbxTo)
//{
// var varFromBox = document.all(lstbxFrom);
// var varToBox = document.all(lstbxTo);
// if ((varFromBox != null) && (varToBox != null))
// {
// if(varFromBox.length < 1)
// {
// alert('There are no items in the source ListBox');
// return false;
// }
// if(varFromBox.options.selectedIndex == -1)
// when no Item is selected the index will be -1
// {
// alert('Please select an Item to move');
// return false;
// }
// while ( varFromBox.options.selectedIndex >= 0 )
// {
// Create a new instance of ListItem
// var newOption = new Option();
// newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text;
// newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value;
//Append the item in Target Listbox
// varToBox.options[varToBox.length] = newOption;
//Remove the item from Source Listbox
// varFromBox.remove(varFromBox.options.selectedIndex);
// }
// }
// return false;
//}
and in Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnMoveRight.Attributes.Add("onclick", "return fnMoveItems('ListBox1','ListBox2')");
btnMoveLeft.Attributes.Add("onclick", "return fnMoveItems('ListBox2','ListBox1')");
}
}
Monday, March 31, 2008
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment