Click here to Skip to main content
13,252,362 members (56,900 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 30 Apr 2005

ListBoxDual Custom Control

, 30 Apr 2005
Rate this:
Please Sign up or sign in to vote.
Implementation time of a web project is much shorter with easy-to-use custom components.


ASP.NET components are used in most of the web projects. But most of the time, the requested solution needs more powerful and easy to use components in order to give a better UI and better control over the project.

In one of the projects, the team needed to collect user information from a ListBox control and write it to another one to display it to the user. It was noticed that this requirement would be repeated several times, so the ListBoxDual custom component was created. It could have been implemented without creating the component but this time that would have been a time consuming task and the developer would lose focus from his problem domain.


In order to handle the ListBox content (which has items inserted dynamically at client-side) at code behind, you should select the inserted items with the client-script before submitting the form. Then you can get the info using Page.Request method in a comma-delimited string.

Using the code

The component class diagram is shown here:

+Size: Int32
+Width: Int32
+RightImageUrl: string
+LeftImageUrl: string
+DataSource: object
+DataTableName: string
+DataValueField: string
+DataTextFied: string
+SelectedItems: DataTable

If you want to add a component to the ToolBox, all you need to do is to drag and drop the component onto the design form. Or you should write the 1st and the 5th lines. (Refer to the demo project.) The LeftImageUrl and RightImageUrl are must or you will get an exception.

1] <%@Register TagPrefix="gm" namespace="gmtl.web.ui" assembly="gmtl.web.ui"%>
2] ...
3]<form id="Form1" method="post" runat="server">
4] ...
5] <gm:listboxdual id="BizListBoxDual1" runat="server" 

LeftImageUrl="picture\ToLeft.gif" RigthImageUrl="picture\ToRight.gif">
6] </form>
7] ...

DataTable or DataSet might be bound to the control. You could specify any table in the DataSet by setting the DataTableName property of the control. Otherwise it will select the first table. After postback, the component's SelectedItems property is used to get the selected key-value pairs in a DataTable. Getting values via Hash Table seems easier but DataTable or DataSet is more intuitive to pass though tiers.

Points of interest

I tried to keep the code easy to understand but implementing the same with composite controls might make the code shorter and easier to follow.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
Turkey Turkey
iOS development, .Net, Ms. Biztalk, and xml related technologies are my main interests.

You may also be interested in...


Comments and Discussions

Generalneat Pin
peter gabris18-Nov-07 8:41
memberpeter gabris18-Nov-07 8:41 
GeneralCode for ASP.NET 2.0 Pin
tcannon18-Oct-06 11:29
membertcannon18-Oct-06 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 30 Apr 2005
Article Copyright 2005 by mtlg
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid