Sorting with Datagrid ViewState disabled
I've talked in the past about sorting a Datagrid without ViewState. The key to getting this to work is calling .DataBind() on the DataGrid during Page_Load in order to wire up the SortCommand event. I wanted to clarify something though, the .DataBind() doesn't have to be to the *real* .DataSource of the Datagrid, it can just be a dummy value. Like so:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
dgReport.DataSource = New DataTable
dgReport.DataBind() 'bind to dummy datasource to wire up SortCommand event (ViewState is disabled)
End Sub Private Sub dgReport_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgReport.SortCommand
...
BindData() 'bind to *real* datasource
End Sub Marcie