Data Controls

We've seen that ADO.NET offers a lot of functionality, but ADO.NET becomes much more when combined with the data-aware server controls.

The DataGrid Control

The workhorse of these controls is the DataGrid. As we've seen in previous examples, this control makes it simple to display data from the database. The simplest way to add a DataGrid is as follows:

<asp:DataGrid id=DataGrid1 runat="server" />

The ID property gives us something we can write code against. By saying runat=server, we can handle server-side events, and change the properties of this control with code.

DataGrid Appearance

Right out of the box, the DataGrid gives you a lot of control over how it looks (see Listing 4.17).

Listing 4.17. Controlling the appearance of ...

Get ASP.NET by Example 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.