How to change the default sort order to descending?

Knox picture Knox · Feb 2, 2011 · Viewed 9.4k times · Source

How do I change the defaultSort of my webGrid to be in the opposite/descending order? If it were SQL, I'd be adding a DESC somewhere. Here's my working line of code for an Ascending sort:

var grid = new WebGrid(dq, rowsPerPage: 50, defaultSort: "UWDate", ajaxUpdateContainerId: "grid" );

It correctly sorts on the UWDate column in Ascending order, but I would like it to sort the opposite/descending order.

Answer

JGood picture JGood · Jan 27, 2013

Another option is after your grid initialization:

    grid.SortDirection = SortDirection.Descending;