If you have work with sorting feature of ASP.NET DataGrid, you must have noticed that the sorting works only for the current page of the grid. As soon as you change the 'state' of the page the sorting is lost (For example when page index is changed). This is because the value of SortExpression is available only in SortCommand event. In order to persist the sorting we need to preserve this value some where. In addition to this we do not have in-built mechanism to perform bidirectional (ascending-descending) sorting. In this small article I will show you how to accomplish these tasks using ViewState object.