Skip to content

Instantly share code, notes, and snippets.

@HamidMosalla
Last active August 17, 2017 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HamidMosalla/b6a345f1467219bd2a900f4222754b33 to your computer and use it in GitHub Desktop.
Save HamidMosalla/b6a345f1467219bd2a900f4222754b33 to your computer and use it in GitHub Desktop.
public List<SelectListItem> GetStockSelectListItemsWithOptionGroup(Company[] companies, Stock[] stocks)
{
var optionGroups = companies.GroupBy(c => c.CompanyId, c => c.CompanyName).Select(c => new SelectListGroup { Name = c.First() });
return stocks.Select(s => new SelectListItem
{
Text = s.StockName,
Value = s.StockId.ToString(),
Group = optionGroups.Single(o => o.Name.Trim() == s.CompanyName.Trim())
}).ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment