I want to multiselect items from an array,
For some reason, this code throws me an NullReferenceException:
int[] players = Playerss.GetAllPlayersIDbyMovieID(movie);
foreach (int playerID in players)
{
PlayersListBox.Items.FindByValue(playerID.ToString()).Selected = true;
}
When I use this code instead, it works but it only keeps the last option selected:
int[] players = Playerss.GetAllPlayersIDbyMovieID(movie);
foreach (int playerID in players)
{
PlayersListBox.SelectedValue += playerID.ToString();
}
ASP .net file:
<asp:ListBox ID="PlayersListBox" runat="server"
SelectionMode="Multiple"
DataSourceID="PlayersAccessDataSource"
DataTextField="Player"
DataValueField="PlayerID"
></asp:ListBox>