CodeSmith Community
Your Code. Your Way. Faster!

Selfpopulated WebControls for enum objects

Latest post 05-21-2007 3:14 PM by tselke. 3 replies.
  • 05-21-2007 4:42 AM

    • acecebov
    • Not Ranked
    • Joined on 05-18-2007
    • Skopje, Macedonia
    • Posts 2
    • Points 70

    Selfpopulated WebControls for enum objects

    I’ve started building web pages using NetTiers and I noticed that there are cases where I have to show some webcontrols that will show enum data. So what I was doing is put for example dropdownlist and bind this control to a datasource. Every time the user requests a page that contains that dropdownlist, the datasource component gets data from sqlserver, right. But this isn’t necessary because the datasource always gets the same data (remember enum tables), why not set ListItems for that dropdownlist component at design time and get rid of the datasource. This way every time the dropdownlist needs to be initialized we don’t need to get data from sqlserver, which means performance improvement. But in practice enum tables in database are not complete, this means that maybe in feature I could add/delete/change some rows in enum tables and then what, I gonna need to go thru all pages and add/delete/change listitems in dropdownlist controls. So I was thinking that it will be nice feature NetTiers to build self populated WebControls for us from tables that are marked for enums. So I build CodeSmith templates for this kind of controls and  I integrated them in NetTiers.

    Download the attachment and extract to an existing NetTiers2.0.1 folder. There are additional templates in WebLibrary\UI directory, also I had to change the FrameworkTemlates.cst file from the TemplateLib dir, CreateTemplates from UserLib dir, vsnet2005.project.cst from VisualStudio dir and the main NetTiers.cst template.

     

    Please tell me what do you think about the controls, and if you can improve them.

    Sorry for my English Big Smile.

    Filed under:
    • Post Points: 35
  • 05-21-2007 7:00 AM In reply to

    • tselke
    • Top 50 Contributor
    • Joined on 04-23-2007
    • Posts 96
    • Points 2,520

    Re: Selfpopulated WebControls for enum objects

    Let me preface this note with the statement that I have not pulled your code and looked at it.  I am assuming certain things from your posting.  Namely, I am assuming that you are generating a series of design-/compile-time List.Add() statements in order to insert each enumeration element into the various lists.  It's a decent idea, but there may be a more elegent solution.

    You can bind a List's DataSource directly to an enumeration like so:

    ddColor.DataSource = Enum.GetNames(typeof(Color));
    ddColor.DataBind();

    This way, any control which uses your enum as a data source will be updated automatically when the enum is updated.  Also, you can add controls manually later without having to loop or query SQL Server.

    Of course, if this is what you are already doing, or you have an even simpler/better way, I apologise for my assumption and I'll have to make some time to take a look.

    Tony

    p.s. :  Sorry.  I had to edit this.  The first code example used an internal function from an old piece of code in my archive. Embarrassed

    • Post Points: 35
  • 05-21-2007 2:39 PM In reply to

    • katokay
    • Top 25 Contributor
    • Joined on 07-09-2006
    • Salt Lake City, UT
    • Posts 143
    • Points 3,190

    Re: Selfpopulated WebControls for enum objects

    Assuming the users of the system want to use PascalCasedStrings or Underscore_Replacements_For_Spaces.
    • Post Points: 35
  • 05-21-2007 3:14 PM In reply to

    • tselke
    • Top 50 Contributor
    • Joined on 04-23-2007
    • Posts 96
    • Points 2,520

    Re: Selfpopulated WebControls for enum objects

    Excellent point!  My bad. Smile
    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems