ObjectDataSource and Sorting (Part 2)

Thursday, 1 June 2006

Sergio asked if I could post how I solved my problem with sorting and the ObjectDataSource control.

Here's what I did:

First of all, add a parameter to the method that is being called by the ObjectDataSource control that will be used to sort the data.

    <DataObjectMethod(DataObjectMethodType.Select)> _
    Public Shared Function GetTests(ByVal sortExpression As String) As TestInfoCollection
        If sortExpression Is Nothing Then
            Throw New ArgumentNullException("sortExpression")
        End If

It's up to you what you do with the value that is passed in. The value comes in looking like the sort bit of SQL. In my case to get things up and running I'm loading my data into a DataTable, then use a DataView to do the sorting for me - not the most efficient way but it works for now. Later on, I might pass the sort criteria down to SQL Server and let it do the sorting for me, but that will require messing with the stored procedures!

It seems like an oversight that there isn't a special attribute to prepend the sortExpression parameter so that the ObjectDataSource recognises it as special - unfortunately it just thinks it's a regular parameter and will add it to the SelectParameters part in the aspx file. You just need to remove it from there and instead make sure the SortParameterName attribute is set instead.

<asp:ObjectDataSource id="odsTests"
<asp:QueryStringParameter ConvertEmptyStringToNull="False" Name="courseId" QueryStringField="CourseId" Type="Object" />


Wednesday, 31 May 2006

Here's a Visual Studio.NET add-in for generating NUnit unit tests

Vista Beta 2

Thursday, 25 May 2006

Windows Vista Beta 2 has been released. I'm downloading it now.

If it looks stable enough then I'll consider reloading my workstation with it (Time to live dangerously!)

WinFX, Office 2007, Threat Modelling Tool, SharePoint v3

Wednesday, 24 May 2006

Poppa Bill

Tuesday, 23 May 2006

Today just after 4pm, my grandfather "Poppa Bill" passed away. It is a really sad day, though in a sense there is a sense of relief that he doesn't have to struggle with his health anymore.

One thing to hang on to is that we will meet again one day in Heaven. Tonight as we put the kids to bed, we thought about some of the things he would now be able to do again that he hadn't for a long time because of poor health - including running around, eating donuts and meat pies! (Poppa had diabetes)

He had a most remarkable life, and I will miss him a lot.

Thanks Poppa.