private void BindSongs() { SongService service = new SongService(Ioc.GetInstance<ISongRepository>()); var songs = service.GetAllSongs().OrderBy(x => x.SongName).ToList(); int finalPosition = 0; ListItem[] collection; if (songs != null) { //Need extra one for the "Please select a song" item collection = new ListItem[songs.Count + 1]; //use song.Count because it has the exact correct amount. Collections length has an extra one for the first item for (int i = 0; i < songs.Count; i++) { collection[i] = new ListItem(songs[i].SongName, songs[i].SongId.ToString()); finalPosition = i + 1; } ListItem item = new ListItem("Please select a song", "-1"); collection[finalPosition] = item; item.Selected = true; lstSongs.Items.AddRange(collection); } }
private void BindWantedList() { var wantedListService = new WantedListService(Ioc.GetInstance<IWantedListRepository>()); var wantedList = wantedListService.GetByUserId(userId); var songService = new SongService(Ioc.GetInstance<ISongRepository>()); var songsWantedList = (from w in wantedList from s in songService.GetAllSongs() where s.SongId.Equals(w.SongId) select new { Song = s, Wanted = w }); rptWantedList.DataSource = songsWantedList; rptWantedList.DataBind(); }