Click here to Skip to main content
13,554,127 members
Rate this:
Please Sign up or sign in to vote.
See more:

I've a linq something like below.

Dim tblL1 = From tb In tblData _
                    Group tb By Company = tb.Company, Plant = tb.Plant, _
                    MaterialType = tb.MaterialType, MaterialGroup = tb.MaterialGroup _
                    Select Company, Plant, MaterialType, _ 
                    MaterialGroup, _
                    Value = FormatCurrency(Math.Round(Group.Sum(Function(tb) tb.PCPValue), 0), 0), _
                    NoOfParcels = Math.Round(Group.Sum(Function(tb) tb.NO_OF_PARCEL), 0) _
                    Order By Company,Plant,MaterialType

            gvData.DataSource = tblL1.ToList

Everything is working properly.
The thing is the sort order will be selected by user.
I've given 3 combos from which user can select the sort order, based on which the o/p should be. So I've declared a variable like this.

 Dim strOrder As String = ""
If cboSortOrder1 <> "" Then
     strOrder &= cboSortOrder1.SelectedValue & ","
End If
'Same as above for nearly 10 columns
If strOrder.EndsWith(",") Then
    strOrder = strOrder.Remove(strOrder.LastIndexOf(","))
End If

And if I replase the order by values with this strOrder, Then no errors but its not getting sorted as desired. I've paging in my gridview. so tbl1.tolist is necessary. Or alternatively if tolist has to be removed then what shold I do?

Its not possible to write the query with each and every combination, B'cas here I've shown only 3 columns. In reality I've more than 10 columns.

How to achieve this?

Thanks in advance...
Posted 20-Jan-13 16:23pm
Updated 20-Jan-13 16:26pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180515.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100