This post will show you how to create TwoSelect User control, basically this control can be used in the scenario where you want to add Users to selected Group. Left side of the ListBox will contain the users which is not present in the group and right side of the ListBox contains the list of users already present in the group.
I have created this as a very Generic control which can be used in other scenarios other then this also. You can customize the Display Text, button captions, some behaviours of the ListBox of this Control.
Also you need to provide the DataSource for the ListBoxes as IDataReader.
This control is built in Visual Studio 2008 with Framework 3.5 sp1, but this can be used in Visual Studio 2005 or Framework 2.0 also.
Following are the list of properties which are exposed in this control with their Types
1: public ListItemCollection AddedItems
3: public ListItemCollection AvailableItems
5: public string AvailableItemText
7: public string AddedItemsText
9: public string AddAllItemsButtonText
11: public string AddSelectedItemsButtonText
13: public string RemoveSelectedItemButtonText
15: public string RemoveAllItemsButtonText
17: public ListSelectionMode AvailableListSelectionMode
19: public ListSelectionMode AddedItemsListSelectionMode
21: public IDataReader DataSourceAvailable
23: public IDataReader DataSourceAdded
25: public string DataTextFieldAvailable
27: public string DataValueFieldAvailable
29: public string DataTextFieldAdded
31: public string DataValueFieldAdded
On click of the 'Add' Button, I am adding the items in the ArrayList and then from ArrayList I am moving from Available Items List Box to Added Items ListBox.
On Click of 'Add All' I am first adding all the items from Available Items to Added Items ListBox, and then clearing all the items from the Available Items ListBox
On click of the 'Remove' Button, I am adding the items in the ArrayList and then from ArrayList I am moving from Added Items List Box back to Available Items ListBox.
On Click of 'Remove All' I am first adding all the items from Added Items List Box to Available Items ListBox, and then clearing all the items from the Added Items ListBox.
In ASPX code I am adding just basic look and feel which will look like the one which is given in the screen shot at the beginning of the Post, but you can extend this control to customize the look and feel.
In this Post, I have given the source code of the Control only, in my next Post I will give the sample implementation of this control, using ASP.NET and LINQ.
You can download the Source Code (C#) and Help File from here.
Sorry for the Code Formatting Guys, but you can always refer my asp.net weblog for my neat and clear code formatting.