vendredi 30 janvier 2015

LINQ query in C# using string on the fly to ORDER data

I have a function with two strings. Can't figure out how to incorporate those two strings into a LINQ query.


Here is my function:



private void DataBind_GridView_Search(string OptionalArgsSortExpression = "", string OptionalArgsSortDirection = "")
{
List<mainSearchDataModel> Query = GetData();
if (Query != null)
{


/* Problem ... */
Query = from x in Query
orderby OptionalArgsSortExpression.ToString() OptionalArgsSortDirection.ToString()
select x;
/* Problem ... */


GridView_Search.DataSource = Query;
GridView_Search.DataBind();
}


Any comments would be highly appreciated.


enter image description here


This is the error I get. Also I am not using DLINQ.


'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.


UPDATE:


Is there a way to ORDER a List or IEnumerable either one. It seems everything I try does not work.


There is a way to convert it to DataView but I run into trouble there as well and would rather not go that way.






Aucun commentaire:

Enregistrer un commentaire