Sorting in WebControl

Posts   
 
    
Posts: 5
Joined: 07-Aug-2006
# Posted on: 27-Oct-2006 16:51:23   

I have a custom control that inherits the standard ASP.NET DropDownList that I built a while ago to bind to tables that contain lookup data.

I set the data object name that I want to bind the control to as a property on my form and then use Reflection and the EntityCollectionBase class in the control to generate my collection.

This all works fine:


System.Reflection.Assembly asm = System.Reflection.Assembly.Load("Sequence.FiveCounties.DAL");
SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase inst = (SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase)asm.CreateInstance("Sequence.FiveCounties.DAL.CollectionClasses." + dataObject + "Collection");
inst.GetMulti(null);

Thing is because of one thing and another I need to sort the items before calling DataBind(). I've happily added some properties, so things like field name in the collection, direction, that sort of thing, but calling Sort on a Collection requires the FieldIndex as an int. I cannot do the normal (int)MyEntityFieldIndex.MyFieldName because I cannot have the individual collections field indexes as properties, I want to be able to pass in a string for the name.

Is there a way of getting from say a string "MyFieldName" to (int)MyEntityFieldIndex when the collection is not generated until run time?

Thanks.

Posts: 5
Joined: 07-Aug-2006
# Posted on: 27-Oct-2006 17:26:45   

It's okay, must be having Friday moment, it's dead easy.


inst.Sort(sortItem, sortDirection, null)

where sortItem is my string for the column to sort on and sortDirection is ListSortDirection.

D'oh!