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
What does executereader return?
Which object holds only data and does not interact with data source?
What is an orm, and why would you use one instead of plain old ado.net?
What is the difference between linq and ado.net?
What are the namespaces used in ado.net for data access?
What are the important features of ado.net 2.0?
What is dataset object? Explain the various objects in dataset.
What is a non query?
Explain the different row versions available in table?
How can you identify whether or not any changes are made to the DataSet object since it was last loaded?
How can we load multiple tables in to dataset?
How to store data in memory?
What is ado and rdo?
Does sqlclient and oledb class share the same functionality?
What is Serialization in .NET? what are the types of Serialization?