I had the idea to extend the System.Web.UI.WebControls.BoundField to make my own class EntityField class that would be primarily based on a given EntityField2 parameter.
So instead of setting the DataField etc. properties in the aspx file, I wanted to create something along the lines of:
public EntityField(EntityField2 field, string headerText, SortDirection standardSortDirection)
:
base()
{
this.Field = field;
this.HeaderText = headerText;
this.DataField = field.Name;
this.SortExpression = field.Name;
this._standardSortDirection = standardSortDirection;
}
That would be for example later used as following to create columns/fields of a given GridView:
_columns = new DataControlField[] {
new EntityField(TeamSiFields.Id, "Id", SortDirection.Descending),
new EntityField(TeamSiFields.Season, "Season", SortDirection.Ascending),
new EntityField(TeamSiFields.Team, "TeamId", SortDirection.Ascending)
};
Everything worked perfect so far, until ... I started sorting the columns and the PostBack triggered the LoadViewState() method. Now I constantly get the exception:
System.MissingMethodException: No parameterless constructor defined for this object.
I know one can play around with overriding the LoadViewState() and SaveViewState() methods. But this is quite a pain.
So after hours of work I am wondering if I just wasted a lot of time ... but I assume there must be a descent way to use and extend WebControls and implement functionality based on the LGP entities.
Can somebody give me some hints how to do this properly?