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.