Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have list view items, it contains some 10 items, I have 2 buttons like up and down. We assuming the listview first item is selected, when i click the down button it will goes to second position, same time when i click the up button it will moves to upside.
Like that way the files are moves up and down while click the button.

Using Windows Application with c# code.

Regards
Vasanth
Posted
Updated 13-Sep-12 22:37pm
v2

1 solution

using System;
using System.Collections;
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 r2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {
if(!IsPostBack)
BindData();
}
protected void MoveRight(object sender, EventArgs e) {
while(uxListBox1.Items.Count > 0 && uxListBox1.SelectedItem != null) {
ListItem selectedItem = uxListBox1.SelectedItem;
selectedItem.Selected = false;
uxListBox2.Items.Add(selectedItem);
uxListBox1.Items.Remove(selectedItem);
}
}
protected void MoveLeft(object sender, EventArgs e) {
while(uxListBox2.Items.Count > 0 && uxListBox2.SelectedItem != null) {
ListItem selectedItem = uxListBox2.SelectedItem;
selectedItem.Selected = false;
uxListBox1.Items.Add(selectedItem);
uxListBox2.Items.Remove(selectedItem);
}
}
private void BindData() {
uxListBox1.Items.Add(new ListItem("test1", "test1"));
uxListBox1.Items.Add(new ListItem("test2", "test2"));
uxListBox1.Items.Add(new ListItem("test3", "test3"));
}
}

.aspx

XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="uxListBox1" runat="server" SelectionMode="multiple" />
        <asp:Button id="uxRightBtn" runat="server" OnClick="MoveRight" Text=" > " />
        <asp:Button id="uxLeftBtn" runat="server" OnClick="MoveLeft" Text=" < " />
        <asp:ListBox ID="uxListBox2" runat="server" SelectionMode="multiple" />
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
vasanthkumarmk 14-Sep-12 4:37am    
I am using windows Application with C# language.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900