Brian Desmond's Blog

Inherits Network.Admin
Implements IOneManBand

Datagrid Sorting with Viewstate Disabled

I learnt how to enable sorting on a datagrid with Viewstate disabled for the grid. Quite simple, actually - here's how:

You have to rebind on every page load, and manually put the SortExpression in Viewstate:

Sub Page_Load (sender as Object, e as EventArgs) Handles MyBase.Load
     ' Note that you CANNOT enclose in the usual If Not Page.IsPostback block!
     
      myGrid.DataSource = myDataSet
      myGrid.DataBind()
End Sub

Sub myGrid_SortCommand(sender as Object, e as DatagridSortCommandEventArgs)
      Viewstate(“SortExpression“) = e.SortExpression

      myGrid.DataSource = mySortedDataset
      myGrid.DataBind()
End Sub

That's it! You'll, of course, find your page size to be much much smaller if viewstate is disabled on the grid.

Posted: Feb 01 2004, 06:55 PM by bdesmond | with no comments
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)