I am new to VB.NET. I am working with VS 2003.
My issue is that I want to sort the current binded datagrid without going back to the database to obtain the records based on the new sort criteria selected by the user.
Upon intially loading the datagrid was binded using a collection.
Public Class NewCompCollection
Inherits ArrayList
End Class
I have been researching and all documentation refers to datasets or dataviews or going back to the database to resort the data. Can I re-sort the datagrid as I am trying to do below or is more complicated since a collection was used to bind the datagrid. See code below.
ON PAGE LOAD:
Private Function getRecords() As Boolean
Dim NewCollection As NewCompCollection
Dim NewCompRec As New NewCompClass
Dim i As Integer
Try
' get records from Oracle db
NewCollection = NewCompClass.GetRecords()
dgTravel.DataSource = NewCollection
dgTravel.DataBind()
Session("NewCompCol") = NewCollection
Catch ex As Exception
Throw ex
End Try
End Function
HTML DATAGRID CONTAINS:
OnSortCommand="dgTravel_SortCommand"
VB PROCEDURE:
Public Sub dgTravel_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgTravel.SortCommand
' Extract current sort column and order.
Dim currSortExpr As String = dgTravel.Attributes("SortExpr")
Dim newSortExpr As String = e.SortExpression
' If the sort expression is the same as the current 'one,just reverse the direction.
If Not (currSortExpr Is Nothing) AndAlso currSortExpr.ToString = _
e.SortExpression Then
newSortExpr &= " DESC"
End If
dgTravel.Attributes("SortExpr") = newSortExpr
dgTravel.DataSource = ???
dgTravel.DataBind()
End Sub
Thanks for your help in advance !!!!
My issue is that I want to sort the current binded datagrid without going back to the database to obtain the records based on the new sort criteria selected by the user.
Upon intially loading the datagrid was binded using a collection.
Public Class NewCompCollection
Inherits ArrayList
End Class
I have been researching and all documentation refers to datasets or dataviews or going back to the database to resort the data. Can I re-sort the datagrid as I am trying to do below or is more complicated since a collection was used to bind the datagrid. See code below.
ON PAGE LOAD:
Private Function getRecords() As Boolean
Dim NewCollection As NewCompCollection
Dim NewCompRec As New NewCompClass
Dim i As Integer
Try
' get records from Oracle db
NewCollection = NewCompClass.GetRecords()
dgTravel.DataSource = NewCollection
dgTravel.DataBind()
Session("NewCompCol") = NewCollection
Catch ex As Exception
Throw ex
End Try
End Function
HTML DATAGRID CONTAINS:
OnSortCommand="dgTravel_SortCommand"
VB PROCEDURE:
Public Sub dgTravel_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgTravel.SortCommand
' Extract current sort column and order.
Dim currSortExpr As String = dgTravel.Attributes("SortExpr")
Dim newSortExpr As String = e.SortExpression
' If the sort expression is the same as the current 'one,just reverse the direction.
If Not (currSortExpr Is Nothing) AndAlso currSortExpr.ToString = _
e.SortExpression Then
newSortExpr &= " DESC"
End If
dgTravel.Attributes("SortExpr") = newSortExpr
dgTravel.DataSource = ???
dgTravel.DataBind()
End Sub
Thanks for your help in advance !!!!