sorting and paging

  • Thread starter Thread starter Dave S
  • Start date Start date
D

Dave S

Hi,

I'm using a datagrid to display contents of a dataset and I've set the
datagrid to allow paging and sorting.
Rather than re-retrieve from the DB, I store the original dataset in a
Session variable and then rebind to it for each page (which works).
I'd also like to be able to sort any of the columns of the datagrid, so I do
this using a dataview as shown below triggered from the normal
Grid_SortCommand event :

Private Sub ResultGrid_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
ResultGrid.SortCommand
Dim ds As DataSet
ds = Session("myRecs")
Dim dv As New DataView
dv = ds.Tables("myTable").DefaultView
dv.Sort = e.sortExpression
ResultGrid.Datasource = dv
ResultGrid.DataBind()

' store sorted dataset in session ????
End Sub


The above sort works but when I click on my datagrid page links, it loses
the sorting when the page returns.
It tried storing the sorted dataview as below, but it didn't work

Dim dt As DataTable
dt = dv.Table.Copy()
ds = New DataSet(dv.Table.TableName)
ds.Tables.Add(dt)
Session("myRecs") = ds


Any ideas how I can retain sorting and paging together ???

Thanks
Dave
 
Don't know if anyone's looked at my post below, but no need to bother now
I've figured out a way of doing it.
I saved the sortExpression in the session along with the dataset, if a
sortexpression existed in the session, I loaded the dataset into a dataview
and re-applied the sortexpression and paging was automatically applied along
with the correct sort order.
 
Back
Top