Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: LINQVB.NET
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
Edited 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
Your Filters
0 Shai Vashdi 963
1 Tadit Dash 270
2 Sergey Alexandrovich Kryukov 250
3 OriginalGriff 233
4 Peter Leow 180
0 Sergey Alexandrovich Kryukov 9,435
1 OriginalGriff 5,498
2 Peter Leow 4,230
3 Maciej Los 3,540
4 Abhinav S 3,353

Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid