In this article we will look at the steps for building such a custom control as well as how to use the control in an ASP. The custom control's complete source code and a demo application are available for download at the end of this article. If you have programmatically bound data to the Grid View, then you will need to create an event handler for the property is toggled.

For more information on these enhancements, see: Improving the Sort Arrows Grid View Control.

Since the Bound Field is the only Grid View field that HTML encodes its data, this hack is only needed for the Bound Field.

CRUD is an acronym (short form) for create, read, update and delete.

We often use these four basic functions to perform database operations such as, inserting, retrieving, modifying etc. We first need a table, on which we do the CREATE TABLE [dbo].[Books]( [Book ID] [int] IDENTITY(1,1) NOT NULL, [Book Name] [varchar](50) NULL, [Category] [varchar](50) NULL, [Price] [numeric](18, 2) NULL PRIMARY KEY CLUSTERED ( [Book ID] ASC ) ) ON [PRIMARY] respectively.

However, if you attempt to update a Grid View's field's properties during the databinding stage, the field reports to the Grid View that its state has been changed and that the data needs to be re-bound.

Consequently, I ended up stuck in an infinite loop: The "HTML Encoding Gotcha" outlined here is no longer an issue with the enhancements made to this control on February 6th, 2008.

I created a class named method that is called each time a row is added to the Grid View, including the header row.

My first thought was to override this method and, for the header row, enumerate the fields and update each column's appropriately (removing any image markup first, and then adding the up or down arrow image for the sorted row).

Consequently, the grid displays the standard up and down arrow images (see the first screen shot below).

If you want to use custom arrow images, specify the URL either declaratively or programmatically. The demo page includes a checkbox that allows you to toggle between using the default arrow images and custom ones.

In Part 18 of the An Extensive Examination of the Data Grid Web Control article series, I showed how to dynamically update a sortable Data Grid's header columns so that an up or down arrow image would appear next to the sorted column name depending on whether the column was sorted ascendingly or descendingly (view a live demo).