Specifying That a DataGrid Is to Be Sortable

As we have seen in our previous DataGrid examples, a DataGrid, by default, is not considered sortable. To make a DataGrid sortable, we must check the “Allow sorting” checkbox in the DataGrid's Property Builder. Furthermore, if we are explicitly specifying which columns should appear in the DataGrid, it is vital that we specify which of these columns is sortable.

To examine the steps needed to make a DataGrid sortable, create a new ASP.NET Web page named SortData.aspx. Drag and drop a DataGrid Web control from the Toolbox and onto the designer. (You may want to turn glyphs on, as sortable DataGrids must be placed within the page's Web form.) Set the DataGrid's ID property to dgBooks.

This DataGrid will ...

Get SAMS Teach Yourself ASP.NET in 24 Hours 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.