Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

Introduction

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.

Background

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:

ListBoxDual
+Size: Int32
+Width: Int32
+RightImageUrl: string
+LeftImageUrl: string
+DataSource: object
+DataTableName: string
+DataValueField: string
+DataTextFied: string
+SelectedItems: DataTable
+DataBind()

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.

License

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

Share

About the Author

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

Comments and Discussions

 
Generalneat Pinmemberpeter gabris18-Nov-07 7:41 
GeneralCode for ASP.NET 2.0 Pinmembertcannon18-Oct-06 10:29 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 30 Apr 2005
Article Copyright 2005 by mtlg
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid