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
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