SortedBindingList in GridView (web page) Not Sorting

SortedBindingList in GridView (web page) Not Sorting

Old forum URL: forums.lhotka.net/forums/t/7807.aspx


AndrewR posted on Saturday, October 17, 2009

Hello,

My users got so accustomed to having sorting on my Winforms, and now I am trying the same SortedBindingList implementation for my web page, but it doesn't work (the gridview is not sortable).

Does the CslaDataSource support sorting out of the box?

I'd really appreciate something pointing out how to implement sorting for web pages. I couldn't find any recent post on this subject on the forum.

I'm using VS 2008, CSLA 3.5

Thanks,

Andrew

JoeFallon1 replied on Monday, October 19, 2009

http://forums.lhotka.net/forums/thread/32764.aspx

Joe

 

cslasoup replied on Thursday, June 09, 2011

I know this is an older thread but in case anyone came across this question (and there are a lot of them I've found), this is how I solved this problem...

I have the following classes as part of a messaging module:

<Serializable()> _
Public Class MessageList
    Inherits ReadOnlyListBase(Of MessageList, MessageInfo)

<Serializable()> _
Public Class MessageInfo
    Inherits ReadOnlyBase(Of MessageInfo)

The MessageList class is used in the Messages.aspx page; Here are the related Messages.aspx.vb code-behind functions/methods:

''' <summary>
''' Retrive the MessageList object from session; if it doesn't exist, retrieve it and put it in session
''' </summary>
''' <returns>
''' A MessageList object
''' </returns>
''' <remarks></remarks>
Private Function GetMessageList() As MyObject.Library.MessageList

    Dim businessObject As Object = Session("currentObject")
    If businessObject Is Nothing OrElse Not TypeOf businessObject Is MessageList Then

        businessObject = MyObject.Library.MessageList.GetMessageList()

        Session("currentObject") = businessObject
   
    End If

    Return CType(businessObject, MyObject.Library.MessageList)

End Function

''' <summary>
''' GridView Select event
''' </summary>
''' <remarks></remarks>
Protected Sub MessageListDataSource_SelectObject(ByVal sender As Object, ByVal e As Csla.Web.SelectObjectArgs) Handles MessageListDataSource.SelectObject

    Dim msgList As MessageList = GetMessageList()
    If String.IsNullOrEmpty(e.SortExpression) Then
        e.BusinessObject = msgList
    Else
        Dim msg As New SortedBindingList(Of MessageInfo)(msgList) 'This was what gave me the most trouble
        msg.ApplySort(e.SortProperty, e.SortDirection)
        e.BusinessObject = msg

    End If

End Sub

 

The classes I use are based off of the ProjectTracker example and this solution was based on a solution I found on the forums here: http://forums.lhotka.net/forums/p/7999/38265.aspx

Hope this helps someone.

Copyright (c) Marimer LLC