2

I'm using SPGridview with LinqDataSource and Generic List. I'm having problem when try to do grouping after sorting. Please refer to the screen shot below.

enter image description here

Its grouping in the order of the previous states even though I will order first my data before binding. It's work fine if I don't do any sorting first before grouping. The grouping value is based from a DropDownList.

Appreciate any helps. Thanks In Advance.

1 Answer 1

1

Yeah this is an annoying issue with the SPGridView. It expects the data to be sorted by the column you are grouping by.

// _grid is an SPGridView
_grid.Sort("Category", SortDirection.Ascending);

However, only your Grouping will be sorted and not the rows within each group. What you really need to do is NOT use SPGridView.Sort. Make sure the data is pre-sorted.

For example, here is how I do it using a DataView.

// view is a DataView in this example
// first column has to be the column you are grouping by
view.Sort = string.Format("{0}, {1}", "Category", "ReferenceNumber");

Looks like for the LinqDataSource, you would use Sort By and Then By.

2
  • Thanks, I solved it by using OrderBy("category").ThenBy("Title"). And the trick is that if the dropdownlist selected index > 0 then i will disable AutoSort of the LinqDataSource. Thanks again. Commented Oct 12, 2011 at 11:18
  • 1
    I am facing the same issue . Can you please post the exact code . Commented Apr 26, 2014 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.