Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

LookupItem Class for DropDownLists - .NET Framework

RSS
Modified on Thu, Apr 25, 2013, 5:02 PM by Administrator Categorized as ASP·NET MVC, ASP·NET Web Forms, ·Net Framework

LookupItem Class

public class LookupItem
{
    public virtual string Descrip { get; set; }
    public int ID { get; set; }

    public static string ListToJson(List<LookupItem> items)
    {
        var result = new List<string>();

        foreach (var item in items)
            result.Add(item.ID.ToString() + ":" + item.Descrip);

        return string.Join(";", result.ToArray());
    }
}

LookupItem Extension Methods

public static class LookupManager
{
    public static List<LookupItem> Nullify(this List<LookupItem> result, string nullValue)
    {
        if (nullValue != null)
            result.Insert(0, new LookupItem { Descrip = nullValue, ID = -1 });

        return result;
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.