Datagrid sorting

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I have read most messages in regard with this topic, and have tried
every measure suggested. I'm still haveing problem to get it to work.
Basically, the page just reloaded as before when I clicked on the
header link.
Here is the code :
************************************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim lastSortOrder As String
Dim lastSortColumn As String

daStaffList.Fill(dsStaffList)

If Not IsPostBack Then
ViewState("LastSortOrder") = "ASC"
ViewState("LastSortColumn") = "LastName"
dvStaffList.Sort = "LastName" & " " & " ASC"
daStaffList.Fill(dsStaffList)
dgStaffList.DataBind()
End If
End Sub

Private Sub dgStaffList_SortCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dgStaffList.SortCommand
Dim newSortColumn = e.SortExpression.ToString()
Dim newSortOrder = "ASC" 'Default value
Dim lastSortColumn = ViewState("LastSortColumn")
Dim lastSortOrder = ViewState("LastSortOrder")


If (newSortColumn.Equals(lastSortColumn) And
lastSortOrder.Equals("ASC")) Then
newSortOrder = "DESC"
End If

ViewState("LastSortOrder") = newSortOrder
ViewState("LastSortColumn") = newSortColumn

dvStaffList.Sort = newSortColumn & " " & newSortOrder
daStaffList.Fill(dsStaffList)
dgStaffList.DataBind()

End Sub
******************************************************************************

Any help is appreciated

Simon
 
Hi Simon,

Could you verify that you have the following methods registered under
InitializeComponent(); ?

this.dgStaffList.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dgStaffList_S
ortCommand);

Thanks,
Blaise Pascal Tine (MSFT)
--------------------
 
No, I don't have that method registered.
How would I do that ? and where this code goes?
Thanks
 
Back
Top