Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've a linq something like below.

VB
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.

VB
 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
Updated 20-Jan-13 16:26pm
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900