How do you sort the data in datagrid?

Answer Posted / shiva

Protected Sub Sorting(ByVal sender As Object, ByVal e As
GridViewSortEventArgs)
Dim DESCENDING As String = "DESC"
Dim ASCENDING As String = "ASC"

Dim sortExpression As String = e.SortExpression
If GridViewSortDirection = SortDirection.Ascending
Then
GridViewSortDirection = SortDirection.Descending
SortGridView(sortExpression, DESCENDING)
Else
GridViewSortDirection = SortDirection.Ascending
SortGridView(sortExpression, ASCENDING)
End If
End Sub
(Call this onsorting in datagrdi)
2)
Public Property GridViewSortDirection() As SortDirection
Get
If ViewState("sortDirection") Is Nothing Then
ViewState("sortDirection") =
SortDirection.Ascending
End If
Return CType(ViewState("sortDirection"),
SortDirection)
End Get
Set(ByVal value As SortDirection)
ViewState("sortDirection") = value
End Set
End Property
3) Private Sub SortGridView(ByVal sortExpression As String,
ByVal direction As String)
Try
Dim dt As DataTable = BindData().Tables(0)
Dim dv As New DataView(dt)
dv.Sort = sortExpression + " " + direction
gdvCamp.DataSource = dv
gdvCamp.PageIndex = 0
gdvCamp.DataBind()

Catch ex As Exception
Response.Write(ex.Message)
End Try

End Sub 'SortGridView

Bing the data like fallows
Private Function BindData() As DataSet
Binding Goes here which should returns dataset to above
function
End FUnction

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give an example that shows how to execute a stored procedure in ado.net?

827


Which database is the ado.net sql connection object designed for?

852


What is the namespaces being used to access oracle database?

773


What do you mean by performing asynchronous operation using command object?

786


What are all the classes that are available in System.Data Namespace?

805


What is datasource in ado.net?

855


What is ado.net architecture?

715


Do we use stored procedure in ADO.Net?

784


What do you know about ADO.NET's objects and methods?

753


What is the difference between OLEDB Provider and SqlClient?

757


What is difference between executenonquery and executequery?

740


What is the default provider in ado.net?

730


What is ado.net in vb net?

720


What is serialization and de-serialization in .net? How can we serialize the dataset object?

752


What is ado.net and its features?

766