[Download Code]
In Part 1 and Part 2 of this series, we successfully built the DataGridHelper control that can be used to develop a data access page with sorting, paging, deleting, and updating capabilities without writing a single line of code. I have had too much fun to stop now. In Part 3, we will address another limitation of DataGrid and DataGridHelper control--custom columns.
In ASP.NET 1.x, the easiest way to create custom column is by using the TemplateColumn. The TemplateColumn supports one-way databinding to display the data. The update code is not exactly pretty, as seen in a Microsoft QuickStart sample, because we have to find the control from the controls collection of the table cell and extract the value from the control. The up-coming ASP.NET 2.0 will support two-way binding in GridView templates. For ASP.NET 1.x, Marcie Robillard’s MSDN article discussed an excellent idea of custom columns. The code related to the column is packaged in the custom column class instead of an aspx page, making it reusable. Although it takes some up-front cost to develop, custom columns are easier to use than TemplateColumn. The Metabuilders site has a few great custom columns. In this article, we will extend the idea further by giving the custom column class the responsibility to extract user input. We will also extend the DataGridHelper control to work with custom columns.
We will start by creating the necessary interface for the DataGridHelper control to work with custom columns. We will then build two custom columns that support such an interface. We will also discuss how to extend an existing custom column so we can use the DataGridHelper control with any custom column. We will finally demonstrate how to use the custom columns and conclude this article.
Let's define the interface first.