Binding Columns

In real-world scenarios, when you create columns, you need more options than auto-generation offers. Auto-generation does not let you specify the header text, nor does it provide text formatting. Perhaps the strongest reason to opt for manual binding is that auto-generation always displays all columns in the data source in the order in which they are returned.

Caution

If you plan to manually bind columns to your DataGrid control, make sure you explicitly set AutoGenerateColumns to false. You can do that either declaratively or programmatically. Otherwise, the DataGrid control will place extra columns—all the automatically generated columns—after the last column you manually create.

You typically bind columns using the <columns> ...

Get Building Web Solutions with ASP.NET and ADO.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.