Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Web.Mvc;
- namespace WebSite1 {
- public class ListDataItem<TKey> {
- string _display;
- TKey _key;
- public TKey Key {
- get { return _key; }
- set { _key = value; }
- }
- public string Display {
- get { return _display; }
- set { _display = value; }
- }
- public override string ToString () {
- return Display;
- }
- public ListDataItem () {}
- public ListDataItem (TKey key_, string display_) {
- Key = key_;
- Display = display_;
- }
- public ListDataItem (string display_) {
- Display = display_;
- Key = default(TKey);
- }
- #region Static
- public static List<SelectListItem> ToSelectList(ListDataItem<TKey>[] items){
- List<SelectListItem> selectList = new List<SelectListItem>();
- foreach (var item in items) {
- selectList.Add(new SelectListItem(){
- Text = item.Display,
- Value = item.Key.ToString(),
- Selected = false,
- });
- }
- return selectList;
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment