ASP.Net Datagrid sort

G

George Zolla

I can sort the contents of a datagrid using the following code but when I
change to another page in the dataset I lose the sort. How do I sort the
dataset and keep it when I go to a new page?

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
DataGrid1.SortCommand

Dim DataView1 As New DataView(DsTerritories1.Territories)

DataView1.Sort = e.SortExpression

DataGrid1.DataSource = DataView1 'need this to rebind grid

DataGrid1.DataBind()

End Sub

Here is the paging code:

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
DataGrid1.PageIndexChanged

'need to rebind the datgrid to the source after the page is changed

'However if a sort is performed before the page change the sort is lost

'Need to have dataview with scope for entire project to correct this.

DataGrid1.CurrentPageIndex = e.NewPageIndex

DataGrid1.DataSource = DsTerritories1.Territories

DataGrid1.DataBind()

End Sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top