469,572 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

sorting and paging

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.DataGridSortCommandEvent Args) 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
Jul 21 '05 #1
1 1545
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.
"Dave S" <da********@hotmail.com> wrote in message
news:bb******************************@news.teranew s.com...
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.DataGridSortCommandEvent Args) 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

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Hajime Kusakabe | last post: by
1 post views Thread by Guoqi Zheng | last post: by
2 posts views Thread by saleek | last post: by
1 post views Thread by Dave S | last post: by
5 posts views Thread by LDD | last post: by
2 posts views Thread by Kuldeep | last post: by
reply views Thread by Roy | last post: by
1 post views Thread by John A Grandy | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.