Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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. –  Agamand The True Oct 12 '11 at 11:18
    
I am facing the same issue . Can you please post the exact code . –  sandy_9866141457 Apr 26 at 19:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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