Oct 01 2006

Using Enums to drive DropDownLists

Published by sethyates at 2:42 am under Development

Mark came up with an idea to use Enums to drive lookups. I told him I could go one better by providing user-friendly names instead of programmer-friendly enum value names. The idea is to loop through the literal fields of the enum type and check for a DescriptionAttribute on each field. Anyway, here’s the source, with caching for top performance.

Related posts

3 Responses to “Using Enums to drive DropDownLists”

  1. Mark Cohenon 01 Oct 2006 at 2:49 am

    not only perfected but optimised and full of 2.0 goodness :)

    Nice one!

  2. Barryon 12 Oct 2006 at 6:16 pm

    Very nice, but not quite perfect as you could:

    1) Remove the extra namespaces

    using System.Web.UI.WebControls;
    using System.Collections.Generic;

    2) Seal the class
    public sealed class EnumDataSource

    I’m using the current class, so I thought it would fair to post the changes I made to the class.

    Nit picking, I had to add my 2 cents.

    Cheers.

  3. Barryon 12 Oct 2006 at 6:20 pm

    sorry about that, got posted the wrong namespace
    should have been:

    using System.ComponentModel
    using System.Web.UI.WebControls.

    Cheers

Trackback URI | Comments RSS

Leave a Reply