public static void Show(ListBox lb, User_Type type) { try { lb.DataTextField = "FullName"; lb.DataValueField = "UserID"; using (FruitShopEntity db = new FruitShopEntity()) { var list = db.Users.Where(x => x.Type == type) .Select(x => new { x.UserID, FullName = x.Name + " " + x.Family, }) .ToList(); lb.DataSource = list; } lb.DataBind(); } catch (Exception) { } }
public static void Show(GridView gv, User_Type type) { try { string[] t = new string[1]; t[0] = "UserID"; gv.DataKeyNames = t; using (FruitShopEntity db = new FruitShopEntity()) { var list = db.Users.Where(x => x.Type == type).ToList(); gv.DataSource = list; } gv.DataBind(); } catch (Exception ee) { } }