Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ VB.NET
Hi,
 
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 17:23pm
thams1.3K
Edited 20-Jan-13 17:26pm
v2

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

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2014
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