Click here to Skip to main content
15,881,204 members
Articles / Web Development / HTML
Article

ListBoxDual Custom Control

Rate me:
Please Sign up or sign in to vote.
4.38/5 (4 votes)
30 Apr 20052 min read 94.8K   1.2K   36   2
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.

ASP.NET
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



Comments and Discussions

 
Generalneat Pin
peter gabris18-Nov-07 7:41
peter gabris18-Nov-07 7:41 
GeneralCode for ASP.NET 2.0 Pin
tcannon18-Oct-06 10:29
tcannon18-Oct-06 10: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.