Sort Clause based on name of field

Posts   
 
    
adhesion
User
Posts: 7
Joined: 20-Nov-2006
# Posted on: 31-Dec-2006 20:58:08   

I'm implementing custom paging and sorting on my ASP.NET grid control so that I only have to bring back a minimum number of records from the database. I can wire up the column header click event on the column and grab the columns that are sorted. From there I can get the datamember name which is equivalent to the field name in the database and in the LLBLGen generated code.

I need to be able to build a SortExpression based on the string value name of the datamember. Is there a way to do this with a sortclause/sortexpression?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Jan-2007 08:26:35   

The SortExpression takes a SortClause in the constructor.


SortExpression sorter = new SortExpression(new SortClause(entity.Fields[fieldName], sortOperator.Ascending));
adhesion
User
Posts: 7
Joined: 20-Nov-2006
# Posted on: 02-Jan-2007 02:53:47   

That looks good, but I'm using a dynamic list. So the columns will represent fields from various entities. Any ideas of how to approach this?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Jan-2007 06:11:57   

Check out the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7299

Although I think you already re-build your DynamicList upon sorting, in this case you may just use the following way:


ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(CustomerFields.LastName, 0);
fields.DefineField(CustomerFields.FirstName, 1);
...
SortExpression sortExpression=new SortExpression( new SortClause(fields[x],SortOperator.Ascending));

And change the index x of the fields array in the sortClause constructor according to the clicked column.