Skip to main content


Showing posts from March, 2007

Implementation of paging and sorting for the GridView control that works with an array of objects

Fairly often, such a data presentation model is used: an array of objects is bound to a GridView control with predefined columns. This model was popularized by the DotNetNuke web framework and has the advantage of working with the business objects instead of nameless rows of a data table. A classic example:
<asp:GridView id="gv" runat="server" AutoGenerateColumns="False" ...
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

and elsewhere in Page_Load:
if (!IsPostBack)
gv.DataSource = someArray;

A pretty good model, in my opinion. But, the GridView control does not have built-in ability for sorting and paging if it is bound to an array of objects. Let's implement it.
The code overviewI inherit my control from the GridView control and override the OnInit method in order to add two event handle…