WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
Like every Web control in the ASP.NET toolbox, the GridView includes a variety of style-related properties, including
CssClass, Font, ForeColor, BackColor, Width, Height, and so on. The GridView also includes style properties that apply to certain classes of rows in the grid, such as
RowStyle, AlternatingRowStyle, HeaderStyle, and
PagerStyle. Each of these meta-style properties offer the standard style properties (CssClass, Font, etc.) as subproperties.
In ASP.NET 4.0, Microsoft added four new style properties to the GridView control:
SortedAscendingHeaderStyle, SortedAscendingCellStyle, SortedDescendingHeaderStyle, and
SortedDescendingCellStyle. These four properties are meta-style properties like
HeaderStyle, but apply to column of cells rather than a row. These properties only apply when the GridView is sorted--if the grid's data is sorted in ascending order then the
SortedAscendingCellStyle properties define the styles for the column the data is sorted by.
The SortedDescendingHeaderStyle and
SortedDescendingCellStyle properties apply to the sorted column when the results are sorted in descending order.
These four new properties make it easier to customize the appearance of the column by which the data is sorted. Using these properties along with a touch of Cascading Style Sheets (CSS) it is possible to add up and down arrows to the sorted column's header to indicate whether the data is sorted in ascending or descending order. Likewise, these properties can be used to shade the sorted column or make its text bold. This article shows how to use these four new properties to style the sorted column. Read on to learn more!