Sorting data by a string representation of a fieldname

Posts   
 
    
cjmos
User
Posts: 15
Joined: 04-May-2007
# Posted on: 18-Jul-2007 14:39:15   

Hi,

I'm trying to bind an IDataReader to a GridView. I'm using TypedListDAO.GetAsDataReader. Problem is, I need to create a SortExpression based the string name of the (since that's what I'll get from the GridView_Sorting event). I can't find how ot do this, is it possible?

Thanks in advance,

Chris Moseley

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jul-2007 15:12:35   

Just set the SortExpression property in the column declaration in the aspx page to the corresponfing field name.

siegemos
User
Posts: 47
Joined: 25-Jun-2007
# Posted on: 18-Jul-2007 15:30:29   

Sorry, my original post wasn't clear (even to me, as it seems I forgot how to speak English during some of it).

I have no problem getting hold of the string representation of the field name from the GridView, the problem I'm having is in constructing the ISortExpression in my code. I need to do something like this:



protected void SortGrid(string sortFieldName)
{
    ....
    SortExpression sorter = new SortExpression(new SortClause(fields[sortFieldName], SortOperator.Ascending))
    ....
    return dao.GetAsDataReader(...);
}

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jul-2007 15:55:05   

Try the following:

MyEntity myEntity = new MyEntity();
SortExpression sorter = new SortExpression(new SortClause(myEntity.Fields[sortFieldName], SortOperator.Ascending))
siegemos
User
Posts: 47
Joined: 25-Jun-2007
# Posted on: 18-Jul-2007 16:07:16   

Good stuff, thanks.