Custom Data Binding for Server Controls
page 1 of 7
Published: 09 Mar 2004
Unedited - Community Contributed
Abstract
Data binding is as easy as 1, 2 and 3 for the page developer. However, creating server controls that will accept data from a custom data source can be tricky because few have an idea where to begin. Justin Lovell demonstrates how to do custom data binding.
by Justin Lovell
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 51422/ 224

Introduction

First Article – The Basics of Building Server Controls
Second Article – Reusing and Creating Server Controls

Third Article – Building Composite Server Controls

Fourth Article – The Basics of Templates in Server Controls (previous article)

 

Download the entire source demonstrated in this article

 

For every control developer, providing a simple interface for the page developer to data bind data to a custom server control is far harder than what you may anticipate. In this article, I will give a simple solution; yet, an effective solution for the control developer so that the custom data binding is no longer one of those silly worries.

 

Also in this article, I will demonstrate the data binding by building a simple list control. I will not go into much depth because this article will become too verbose. The objective of the article is to demonstrate the data binding technique – it is not here to show a complete server control.

 

The first question that control developers ask me is – “Where would I begin to create a custom data binding solution to my server control?” For some of you out there, you might have a feint idea where to begin – the starting point is to iterate through a collection.

 

To simply put it down, ASP.NET focuses on binding to controls that implement the ICollection interface. The only reason that I made mention of this is for anyone that wants to create a custom data source (create their own collection with their own objects), ensure that your object implements the ICollection interface – as long the objects inside the collection expose properties. I will put more emphasize on this a later stage in the article.

 

But for now, we will only bind to any object that implements the IEnumerable interface.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 5 and 1 and type the answer here:

User Comments

Title: Why Doesn't It Work   
Name: Marc
Date: 6/4/2009 3:09:50 PM
Comment:
My TitleDescriptionItems never display. CreateChildControlsnever gets hit. Why?
Title: DataSourceID   
Name: Andrew
Date: 6/20/2008 11:11:26 AM
Comment:
Great article, however I was wondering how would one implement the DataSourceID and DataMember properties?

Product Spotlight
Product Spotlight 






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


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 11/8/2009 3:35:02 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search