.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Drag records from one Listbox to other one

Posted By:satyapriyanayak       Posted Date: May 01, 2013    Points: 40    Category:    URL: http://www.dotnetspark.com  

Here 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
 

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="&lt;|" />
   <asp:Button ID="Button2" runat="server" Text="|&gt;" />
   <asp:Button ID="Button3" runat="server" Text="&lt;&lt;|" />
   <asp:Button ID="Button4" runat="server" Text="|&gt;&gt;" />
    <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


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend