Datagrid sorting

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
 
B

Blaise Pascal Tine

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)
--------------------
 
S

Simon Wang

No, I don't have that method registered.
How would I do that ? and where this code goes?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top