How to extend BoundField with EntityField2 as driving parameter?

Posts   
 
    
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 03-Feb-2009 23:33:42   

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?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Feb-2009 06:24:16   

I assume you want this for automate in a relative way the databinding. Why not go on the templates way? Have you checked the "ASP 2.0 GUI Generator Templates" (downloadable from Customer area -> 2.6 -> Tasks and Templates). It used custom properties on Entities and Entity fields to generate GUI templates.

David Elizondo | LLBLGen Support Team
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 04-Feb-2009 15:46:13   

daelmo wrote:

I assume you want this for automate in a relative way the databinding. Why not go on the templates way? Have you checked the "ASP 2.0 GUI Generator Templates" (downloadable from Customer area -> 2.6 -> Tasks and Templates). It used custom properties on Entities and Entity fields to generate GUI templates.

thank you for the hint, I am in the process of looking through the templates right now.

In the meantime, I would like to ask whether you can point me to some "literature" (tutorials, documentation, etc.) on how to achieve our goals/requirements using templates?

We are developing a web site that is mostly basketball statistics oriented. A few examples of the requirements for the GridViews (beside the "usual" functionalities like sorting, filtering, etc.) would be:

-) Show stats in different display modes (totals, averages, 40min averages) depending on the user's choice -) Grid columns based on multiple data source columns with logic driven by data display mode -) Sorting based on column type -) Formatting of columns and rows (text alignment base on type (numerical or not) of data in the column -) Ajax driven tool tips, player profiles and similar gadgets

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Feb-2009 17:17:36   

I think Daelmo suggested to generate the BoundField extended classes with you rgenerated code based on the EntityFields generated.

For more info about templates and code generation, please check the SDK documentation available in the SDK package found in the download section of our website.

magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 04-Feb-2009 17:24:39   

Walaa wrote:

I think Daelmo suggested to generate the BoundField extended classes with you rgenerated code based on the EntityFields generated.

For more info about templates and code generation, please check the SDK documentation available in the SDK package found in the download section of our website.

hmm ... I'm not sure I understand what you mean, but I will try to figure things out from the docu.

In the meantime, two things: 1) I think that the generation of code does not work properly. The .aspx and .cs files are generated, but the .designer.cs files are not. As far as I see this, this is the reason why the generated code won't compile in VS (2005): The element/control Ids addressed in the .cs file are not found.

2) <br> elements are not XHMTL compatible.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Feb-2009 06:48:05   

magic wrote:

Walaa wrote:

I think Daelmo suggested to generate the BoundField extended classes with you rgenerated code based on the EntityFields generated.

For more info about templates and code generation, please check the SDK documentation available in the SDK package found in the download section of our website.

hmm ... I'm not sure I understand what you mean, but I will try to figure things out from the docu.

Generating GUI is tricky. You can't generate a 100% usable GUI. However, if you want, you can generate some usable controls, that is what ASP GUI Templates tries to demostrate.

magic wrote:

In the meantime, two things: 1) I think that the generation of code does not work properly. The .aspx and .cs files are generated, but the .designer.cs files are not. As far as I see this, this is the reason why the generated code won't compile in VS (2005): The element/control Ids addressed in the .cs file are not found.

It works nice to me. The generated code is a "Web Site" not a "Web Application". So, no .designer.cs is needed.

magic wrote:

2) <br> elements are not XHMTL compatible.

You are right. You shouldn't use the templates as the final word on GUI generation. They should be used as an example of generating your own code through templates.

David Elizondo | LLBLGen Support Team
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 05-Feb-2009 14:58:38   

well ... it gives a nice overview, but the problem is that you can't put it into a project/solution because it is not compiling. What would be the problem to generate the .designer.cs files so that it is a fully functional project?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Feb-2009 10:36:39   

It should compile as a WebSite project, not as a Web Application project.

magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 09-Feb-2009 19:41:44   

Walaa wrote:

It should compile as a WebSite project, not as a Web Application project.

stupid question, but ... how do I turn a web application project into a web site projection in VS2005?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Feb-2009 04:28:52   

Do you want to convert from WebSite to WebApp or the opposite?

David Elizondo | LLBLGen Support Team
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 10-Feb-2009 05:32:16   

daelmo wrote:

Do you want to convert from WebSite to WebApp or the opposite?

I have a Web Application Project, but I should have a Web Site Project for the templates to work, right?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Feb-2009 05:50:04   

In VS2005: - Open your solution - Go to File -> Add -> Existing WebSite - Locate your /GUI folder where you generated ASP templates - Click Ok simple_smile - You don't need that WebApp, so you can now delete it.

David Elizondo | LLBLGen Support Team
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 10-Feb-2009 15:24:27   

daelmo wrote:

In VS2005: - Open your solution - Go to File -> Add -> Existing WebSite - Locate your /GUI folder where you generated ASP templates - Click Ok simple_smile - You don't need that WebApp, so you can now delete it.

thanks. Some things are really simple ... if you know what to do. wink

Unfortunately it doesn't seem though as if the web site would work properly. When I run/open the web site that contains the generated templates, it tells me that:

Compiler Error Message: CS0246: The type or namespace name 'Crez' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 8: using System.Web.UI.WebControls.WebParts; Line 9: using System.Web.UI.HtmlControls; Line 10: using Crez.Server.Dal.LGP; Line 11: using SD.LLBLGen.Pro.ORMSupportClasses;

Source File: LGP\Code\GUI\App_Code\GeneralUtils.cs Line: 10

Since I can't add references to a web site ... ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 10-Feb-2009 15:40:27   

Sure you can, right click website in vs.net -> properties -> references

Frans Bouma | Lead developer LLBLGen Pro
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 10-Feb-2009 15:47:44   

Otis wrote:

Sure you can, right click website in vs.net -> properties -> references

ups ... thank you. I think the web site was running, when I was checking this. I'm still getting used to the VS environment ... and am still grieving that I had to give up Eclipse ... cry

The web site is now running without any trouble ... very nice feature! smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 10-Feb-2009 18:25:32   

magic wrote:

Otis wrote:

Sure you can, right click website in vs.net -> properties -> references

ups ... thank you. I think the web site was running, when I was checking this. I'm still getting used to the VS environment ... and am still grieving that I had to give up Eclipse ... cry

Heh, I can imagine simple_smile

The web site is now running without any trouble ... very nice feature! smile

simple_smile

Frans Bouma | Lead developer LLBLGen Pro