In this article I will show
you how to drag records from one listbox to another one and vice versa. Here we
can drag records by selecting it by one by one and also can drag all records
from one listbox to another and vice versa.
Program
Default.aspx
code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled
Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:ListBox ID="ListBox1" runat="server" Width="134px" Height="116px"></asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="<|" />
<asp:Button ID="Button2" runat="server" Text="|>" />
<asp:Button ID="Button3" runat="server" Text="<<|" />
<asp:Button ID="Button4" runat="server" Text="|>>" />
<asp:ListBox ID="ListBox2" runat="server" Width="134px" Height="116px"></asp:ListBox>
</form>
</body>
</html>
Default.aspx.vb code
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub
Page_Load(ByVal sender
As Object, ByVal
e As System.EventArgs)
Handles Me.Load
If Not
IsPostBack Then
ListBox1.Items.Add("Raj")
ListBox1.Items.Add("Ravi")
ListBox1.Items.Add("Rahul")
ListBox1.Items.Add("Raju")
ListBox1.Items.Add("Rohit")
ListBox1.Items.Add("Rajesh")
End If
End Sub
Protected Sub
Button1_Click(ByVal sender
As Object,
ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(ListBox2.SelectedItem.Text)
Dim i As Integer
i =
ListBox2.SelectedIndex
ListBox2.Items.RemoveAt(i)
End Sub
Protected Sub
Button2_Click(ByVal sender
As Object,
ByVal e As
System.EventArgs) Handles Button2.Click
ListBox2.Items.Add(ListBox1.SelectedItem.Text)
Dim i As Integer
i =
ListBox1.SelectedIndex
ListBox1.Items.RemoveAt(i)
End Sub
Protected Sub
Button3_Click(ByVal sender
As Object,
ByVal e As
System.EventArgs) Handles Button3.Click
Dim j As Integer
For j = 0 To
ListBox2.Items.Count - 1
ListBox1.Items.Add(ListBox2.Items(j))
Next
ListBox2.Items.Clear()
End Sub
Protected Sub
Button4_Click(ByVal sender
As Object,
ByVal e As
System.EventArgs) Handles Button4.Click
Dim j As Integer
For j = 0 To
ListBox1.Items.Count - 1
ListBox2.Items.Add(ListBox1.Items(j))
Next
ListBox1.Items.Clear()
End Sub
End Class
Output
