sorting and paging

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
 
D

Dave S

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top