I am having a problem regarding Sort in Gridview. I am not an expert in vb.net but I have to solve this problem. I want to explain how my data is coming in GridView.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
//also there is some logic in there but I think that part of the code will not effect
loadgrid()
End Sub
loadgrid() will load for the query data by going through some steps
//This function is used for some logic
Private Sub loadgrid() Handles B_SEARCH.Click, chkLegacy.CheckedChanged, gvEmployer.PageIndexChanged
GridDataLoader()
End Sub
eEmployer will get all the data for the query for gridView
Public Sub GridDataLoader()
//some code was there because of searching
Dim dataTable = Employer.getEmployers(eEmployer, chkLegacy.Checked)
gvEmployer.DataBind()
End Sub
Public Function GetEmployers(ByVal eEmployer As tblEmployer, ByVal All As Boolean, Optional ByVal sortExpression As String = Nothing) As DataTable
Dim query = ""
query =
"select employer.EmployerID as EmployerId,
employer.Employer_Name as EmployerName,
// the query is so large so i delete all for better understanding
on (employer.Modified_by=tum.UserID)
where employer.LegacyID IS NULL and address.ValidityTo is null"
'End If
Dim params = ""
If All = False Then
query += " AND employer.ValidityTo is null"
End If
If (params.Trim() IsNot "") Then
query = query & params
End If
data.setSQLCommand(query, CommandType.Text)
Return data.Filldata
End Function
finally, the data is returning into grid view. but my problem is I am not understanding how can I implement the sorting thing. i changed something is view AllowSorting="true" SortExpression="EmployerName" and i don't know what should i do further. I was following this Articel
