C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Content Transfer between two Listboxes


Posted Date: 09 Jun 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: Siva Sankari.RMember Level: Gold    
Rating: Points: 7



With this code sample you will able to know about filtering concepts and content transfer from one ListBox to another.



The example is a ASP.NET application and contains .aspx page followed by the C# code.

ASP.NET CODE:


<table>
<tr>
<td style="width: 100px">
Available Fonts</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
Installed Fonts
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:ListBox ID="lstAsset" runat="server" SelectionMode="Multiple" Width="100px">
<asp:ListItem>Roman</asp:ListItem>
<asp:ListItem>Arial Black</asp:ListItem>
<asp:ListItem>Garamond</asp:ListItem>
<asp:ListItem>Somona</asp:ListItem>
<asp:ListItem>Symbol</asp:ListItem>
</asp:ListBox></td>
<td align="center" style="width: 100px">
<asp:Button ID="Button3" runat="server" OnClick="AddBtn_Click" Text=">" Width="29px" /><br />
<asp:Button ID="Button2" runat="server" OnClick="RemoveBtn_Click" Text="<" Width="26px" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="RemoveAllBtn_Click" Text="<<" Width="30px" /><br />
<asp:Button ID="Button4" runat="server" OnClick="AddAllBtn_Click" Text=">>" Width="33px" /></td>
<td style="width: 100px">
<asp:ListBox ID="lstVendors" runat="server" SelectionMode="Multiple" Width="100px">
<asp:ListItem>Times</asp:ListItem>
<asp:ListItem>Helvetica</asp:ListItem>
<asp:ListItem>Arial</asp:ListItem>
</asp:ListBox></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
</table>


C# CODE


using System;
using System.Data;
using System.Configuration;
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;
using System.Text;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
ArrayList lasset = new ArrayList();
ArrayList lsubordinate = new ArrayList();
static ArrayList UpdateList = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{

}
public void AddBtn_Click(Object Src, EventArgs E)
{

if (lstAsset.SelectedIndex >= 0)
{
for (int i = 0; i < lstAsset.Items.Count; i++)
{
if (lstAsset.Items[i].Selected)
{
if (!lasset.Contains(lstAsset.Items[i]))
{
lasset.Add(lstAsset.Items[i]);
}

}
}

for (int i = 0; i < lasset.Count; i++)
{
if (!lstVendors.Items.Contains(((ListItem)lasset[i])))
{
lstVendors.Items.Add(((ListItem)lasset[i]));
}
lstAsset.Items.Remove(((ListItem)lasset[i]));
}
}
}

public void AddAllBtn_Click(Object Src, EventArgs E)
{

while (lstAsset.Items.Count != 0)
{

for (int i = 0; i < lstAsset.Items.Count; i++)
{

if (!lasset.Contains(lstAsset.Items[i]))
{
lasset.Add(lstAsset.Items[i]);
}


}

for (int i = 0; i < lasset.Count; i++)
{
if (!lstVendors.Items.Contains(((ListItem)lasset[i])))
{
lstVendors.Items.Add(((ListItem)lasset[i]));
}
lstAsset.Items.Remove(((ListItem)lasset[i]));
}
}
}

public void RemoveBtn_Click(Object Src, EventArgs E)
{

if (lstVendors.SelectedItem != null)
{

for (int i = 0; i < lstVendors.Items.Count; i++)
{
if (lstVendors.Items[i].Selected)
{
if (!lsubordinate.Contains(lstVendors.Items[i]))
{
lsubordinate.Add(lstVendors.Items[i]);
}
}
}


for (int i = 0; i < lsubordinate.Count; i++)
{
if (!lstAsset.Items.Contains(((ListItem)lsubordinate[i])))
{
lstAsset.Items.Add(((ListItem)lsubordinate[i]));
}
lstVendors.Items.Remove(((ListItem)lsubordinate[i]));
UpdateList.Add(lsubordinate[i]);
}
}
}

public void RemoveAllBtn_Click(Object Src, EventArgs E)
{

while (lstVendors.Items.Count != 0)
{



for (int i = 0; i < lstVendors.Items.Count; i++)
{
if (!lsubordinate.Contains(lstVendors.Items[i]))
{
lsubordinate.Add(lstVendors.Items[i]);
}
}


for (int i = 0; i < lsubordinate.Count; i++)
{
if (!lstAsset.Items.Contains(((ListItem)lsubordinate[i])))
{
lstAsset.Items.Add(((ListItem)lsubordinate[i]));
}
lstVendors.Items.Remove(((ListItem)lsubordinate[i]));
UpdateList.Add(lsubordinate[i]);
}

}
}
}






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Transfer data among listbox  .  Data transfer between Listbox  .  Content Transfer between Listbox  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Adding Controls Dynamically in ASP.NET
Previous Resource: The Process of Uploading and Viewing Photos
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use