Templated DataGrid Controls
As you learned in the first two chapters, the DataGrid control has a table-based structure and is flexible enough to let you determine the structure and contents of columns. Specifically in Chapter 2, you saw DataGrid controls in action and learned how to use their basic yet powerful characteristics. You also learned how to bind special columns representing actions and links. In this chapter, I’ll show you how to use HTML templates to take item customization to the next level. You’ll learn how to design the content of a column so that it closely reflects the meaning and the structure of your data.
Templated columns enable you to use a combination of HTML and server controls to design a custom layout for a column. The controls in a templated column can be bound to any combination of fields in the data source. You can group multiple fields in a single expression and even embellish fields with HTML attributes such as bold or italic. Templates are column-specific and cannot be applied to auto-generated columns. If you want more than one column to share the same template, you can either duplicate the code in the ASP.NET page for each column, or save some code by loading the template from an external file.