Wednesday, April 16, 2008
Paging and Sorting in GridView without using Datasource control:
Private Function ConvertSortDirectionToSql(ByVal sortDireciton As SortDirection) As String
Dim newSortDirection As String = String.Empty
Select Case sortDirection
Case SortDirection.Ascending
newSortDirection = "ASC"
Case SortDirection.Descending
newSortDirection = "DESC"
End Select
Return newSortDirection
End Function
Protected Sub gridView_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
gridView.PageIndex = e.NewPageIndex
gridView.DataBind()
End Sub
Protected Sub gridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Dim dataTable As DataTable = TryCast(gridView.DataSource, DataTable)
If Not dataTable Is Nothing Then
Dim dataView As DataView = New DataView(dataTable)
dataView.Sort = e.SortExpression & " " & ConvertSortDirectionToSql(e.SortDirection)
gridView.DataSource = dataView
gridView.DataBind()
End If
End Sub
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment