Strongly-Typed Binding for List Controls
page 1 of 5
Published: 05 May 2004
Unedited - Community Contributed
Abstract
This article briefly covers the implementation of two types that can be used to bind list controls, such as the DropDownList, in a strongly-typed manner to a SQL Server data source using stored procedures.
by J. Ambrose Little
Feedback
Average Rating: 
Views (Total / Last 10 Days): 24603/ 83

Introduction

[Download Sample Project]

This article briefly covers the implementation of two types that can be used to bind list controls, such as the DropDownList, in a strongly-typed manner to a SQL Server data source using stored procedures.  I think the main application of this concept, as demonstrated by the sample code, is for menu and list controls that usually provide a friendly display value (name or text) and a hidden value, but there may be more.  It could be used in any situation where you need a name-value pair collection. 

The usefulness of this architecture is up for debate--it may be more work than it's worth--but I hope you'll find it is at least an interesting exercise.  Please send me feedback on whether or not you think it is useful, whether you end up using it in a real application, and please rate the article using the rating system that is located at the bottom of the article pages.

There are basically two core types involved in this architecture, the NameValuePair and the NameValuePairCollection.  The NameValuePair type has only two properties--Name and Value.  It is the so-called "business" or "domain" object that represents an individual name-value pair (menu option). 

The second type is, more or less, your standard collection type (the need for which will be replaced with generics in Whidbey), but it does have some custom functionality and data that give this a bit of umph.  There are really three core additions to the basic collection functionality:  FillFromDb, BindToListControl, and the BuildingParameters event (and related argument structure, delegate, and raising method).

 


View Entire Article

User Comments

Title: Well done. Very useful   
Name: Leo
Date: 2009-02-24 8:31:10 AM
Comment:
Hi J. Ambrose Little,

Thanks for your code. I found it very useful indeed.
I used it in a scenario where I needed to create a NameValuePair Collection to concatenate two fields before displaying it on a DropDownList. Without your approach I would have to retrieve an concatenate column field just for my business object in one specific dropdown.

I am using CSLA as framework for the Business Objects. I am looking forward to make it generic with my objects as is not suitable for me use your FillFromDb, because this data is already manipulated by my objects in a business layer.
Unfortunatelly I could not understand the BuildingParamters as I found quite hard to understand events with delegate, etc.

If you have experience with CSLA and have any suggestion to make the Fill up in a generic manner, please let me know.

Thanks a lot.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-06 9:28:54 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search